PHP 클래스 Cake\ORM\Behavior\TranslateBehavior

If you wish to override fields, you need to call the locale method in this behavior for setting the language you want to fetch from the translations table. If you want to bring all or certain languages for each of the fetched records, you can use the custom translations finders that is exposed to the table.
상속: extends Cake\ORM\Behavior
파일 보기 프로젝트 열기: cakephp/orm 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_defaultConfig array These are merged with user-provided configuration when the behavior is used.
$_locale string The locale name that will be used to override fields in the bound table from the translations table
$_table Cake\ORM\Table Table instance
$_translationTable Cake\ORM\Table Instance of Table responsible for translating

공개 메소드들

메소드 설명
__construct ( Table $table, array $config = [] ) Constructor
afterSave ( Cake\Event\Event $event, Cake\Datasource\EntityInterface $entity ) : void Unsets the temporary _i18n property after the entity has been saved
beforeFind ( Cake\Event\Event $event, Query $query, ArrayObject $options ) : void Callback method that listens to the beforeFind event in the bound table. It modifies the passed query by eager loading the translated fields and adding a formatter to copy the values into the main table records.
beforeSave ( Cake\Event\Event $event, Cake\Datasource\EntityInterface $entity, ArrayObject $options ) : void Modifies the entity before it is saved so that translated fields are persisted in the database too.
buildMarshalMap ( $marshaller, $map, $options ) Add in _translations marshalling handlers if translation marshalling is enabled. You need to specifically enable translation marshalling by adding 'translations' => true to the options provided to Table::newEntity() or Table::patchEntity().
findTranslations ( Query $query, array $options ) : Query Custom finder method used to retrieve all translations for the found records.
groupTranslations ( Cake\Datasource\ResultSetInterface $results ) : Cake\Collection\Collection Modifies the results from a table find in order to merge full translation records into each entity under the _translations key
initialize ( array $config ) : void Initialize hook
locale ( string | null $locale = null ) : string Sets all future finds for the bound table to also fetch translated fields for the passed locale. If no value is passed, it returns the currently configured locale
setupFieldAssociations ( array $fields, string $table, string $model, string $strategy ) : void Creates the associations between the bound table and every field passed to this method.

보호된 메소드들

메소드 설명
_bundleTranslatedFields ( Cake\Datasource\EntityInterface $entity ) : void Helper method used to generated multiple translated field entities out of the data found in the _translations property in the passed entity. The result will be put into its _i18n property
_findExistingTranslations ( array $ruleSet ) : array Returns the ids found for each of the condition arrays passed for the translations table. Each records is indexed by the corresponding position to the conditions array
_referenceName ( Table $table ) : string Determine the reference name to use for a given table
_rowMapper ( Cake\Datasource\ResultSetInterface $results, string $locale ) : Cake\Collection\Collection Modifies the results from a table find in order to merge the translated fields into each entity for a given locale.

메소드 상세

__construct() 공개 메소드

Constructor
public __construct ( Table $table, array $config = [] )
$table Cake\ORM\Table The table this behavior is attached to.
$config array The config for this behavior.

_bundleTranslatedFields() 보호된 메소드

Helper method used to generated multiple translated field entities out of the data found in the _translations property in the passed entity. The result will be put into its _i18n property
protected _bundleTranslatedFields ( Cake\Datasource\EntityInterface $entity ) : void
$entity Cake\Datasource\EntityInterface Entity
리턴 void

_findExistingTranslations() 보호된 메소드

Returns the ids found for each of the condition arrays passed for the translations table. Each records is indexed by the corresponding position to the conditions array
protected _findExistingTranslations ( array $ruleSet ) : array
$ruleSet array an array of arary of conditions to be used for finding each
리턴 array

_referenceName() 보호된 메소드

The reference name is usually derived from the class name of the table object (PostsTable -> Posts), however for autotable instances it is derived from the database table the object points at - or as a last resort, the alias of the autotable instance.
protected _referenceName ( Table $table ) : string
$table Cake\ORM\Table The table class to get a reference name for.
리턴 string

_rowMapper() 보호된 메소드

Modifies the results from a table find in order to merge the translated fields into each entity for a given locale.
protected _rowMapper ( Cake\Datasource\ResultSetInterface $results, string $locale ) : Cake\Collection\Collection
$results Cake\Datasource\ResultSetInterface Results to map.
$locale string Locale string
리턴 Cake\Collection\Collection

afterSave() 공개 메소드

Unsets the temporary _i18n property after the entity has been saved
public afterSave ( Cake\Event\Event $event, Cake\Datasource\EntityInterface $entity ) : void
$event Cake\Event\Event The beforeSave event that was fired
$entity Cake\Datasource\EntityInterface The entity that is going to be saved
리턴 void

beforeFind() 공개 메소드

Callback method that listens to the beforeFind event in the bound table. It modifies the passed query by eager loading the translated fields and adding a formatter to copy the values into the main table records.
public beforeFind ( Cake\Event\Event $event, Query $query, ArrayObject $options ) : void
$event Cake\Event\Event The beforeFind event that was fired.
$query Cake\ORM\Query Query
$options ArrayObject The options for the query
리턴 void

beforeSave() 공개 메소드

Modifies the entity before it is saved so that translated fields are persisted in the database too.
public beforeSave ( Cake\Event\Event $event, Cake\Datasource\EntityInterface $entity, ArrayObject $options ) : void
$event Cake\Event\Event The beforeSave event that was fired
$entity Cake\Datasource\EntityInterface The entity that is going to be saved
$options ArrayObject the options passed to the save method
리턴 void

buildMarshalMap() 공개 메소드

{@inheritDoc}
public buildMarshalMap ( $marshaller, $map, $options )

findTranslations() 공개 메소드

Fetched translations can be filtered by locale by passing the locales key in the options array. Translated values will be found for each entity under the property _translations, containing an array indexed by locale name. ### Example: $article = $articles->find('translations', ['locales' => ['eng', 'deu'])->first(); $englishTranslatedFields = $article->get('_translations')['eng']; If the locales array is not passed, it will bring all translations found for each record.
public findTranslations ( Query $query, array $options ) : Query
$query Cake\ORM\Query The original query to modify
$options array Options
리턴 Cake\ORM\Query

groupTranslations() 공개 메소드

Modifies the results from a table find in order to merge full translation records into each entity under the _translations key
public groupTranslations ( Cake\Datasource\ResultSetInterface $results ) : Cake\Collection\Collection
$results Cake\Datasource\ResultSetInterface Results to modify.
리턴 Cake\Collection\Collection

initialize() 공개 메소드

Initialize hook
public initialize ( array $config ) : void
$config array The config for this behavior.
리턴 void

locale() 공개 메소드

Sets all future finds for the bound table to also fetch translated fields for the passed locale. If no value is passed, it returns the currently configured locale
public locale ( string | null $locale = null ) : string
$locale string | null The locale to use for fetching translated records
리턴 string

setupFieldAssociations() 공개 메소드

Additionally it creates a i18n HasMany association that will be used for fetching all translations for each record in the bound table
public setupFieldAssociations ( array $fields, string $table, string $model, string $strategy ) : void
$fields array list of fields to create associations for
$table string the table name to use for storing each field translation
$model string the model field value
$strategy string the strategy used in the _i18n association
리턴 void

프로퍼티 상세

$_defaultConfig 보호되어 있는 프로퍼티

These are merged with user-provided configuration when the behavior is used.
protected array $_defaultConfig
리턴 array

$_locale 보호되어 있는 프로퍼티

The locale name that will be used to override fields in the bound table from the translations table
protected string $_locale
리턴 string

$_table 보호되어 있는 프로퍼티

Table instance
protected Table,Cake\ORM $_table
리턴 Cake\ORM\Table

$_translationTable 보호되어 있는 프로퍼티

Instance of Table responsible for translating
protected Table,Cake\ORM $_translationTable
리턴 Cake\ORM\Table