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
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_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