Fr3nch13/CakePHP Utilities

TranslateStrategyInterface extends PropertyMarshalInterface

This interface describes the methods for translate behavior strategies.

Table of Contents

Methods

afterSave()  : void
Unsets the temporary `_i18n` property after the entity has been saved
beforeFind()  : 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()  : void
Modifies the entity before it is saved so that translated fields are persisted in the database too.
buildMarshalMap()  : array<string|int, mixed>
Build a set of properties that should be included in the marshalling process.
getLocale()  : string
Returns the current locale.
getTranslationTable()  : Table
Return translation table instance.
groupTranslations()  : CollectionInterface
Modifies the results from a table find in order to merge full translation records into each entity under the `_translations` key
setLocale()  : $this
Sets the locale to be used.
translationField()  : string
Returns a fully aliased field name for translated fields.

Methods

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(EventInterface $event, Query $query, ArrayObject $options) : void
Parameters
$event : EventInterface

The beforeFind event that was fired.

$query : Query

Query

$options : ArrayObject

The options for the query

beforeSave()

Modifies the entity before it is saved so that translated fields are persisted in the database too.

public beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options) : void
Parameters
$event : EventInterface

The beforeSave event that was fired

$entity : EntityInterface

The entity that is going to be saved

$options : ArrayObject

the options passed to the save method

buildMarshalMap()

Build a set of properties that should be included in the marshalling process.

public buildMarshalMap(Marshaller $marshaller, array<string|int, mixed> $map, array<string, mixed> $options) : array<string|int, mixed>
Parameters
$marshaller : Marshaller

The marhshaller of the table the behavior is attached to.

$map : array<string|int, mixed>

The property map being built.

$options : array<string, mixed>

The options array used in the marshalling call.

Return values
array<string|int, mixed>

A map of [property => callable] of additional properties to marshal.

getLocale()

Returns the current locale.

public getLocale() : string

If no locale has been explicitly set via setLocale(), this method will return the currently configured global locale.

Return values
string

setLocale()

Sets the locale to be used.

public setLocale(string|null $locale) : $this

When fetching records, the content for the locale set via this method, and likewise when saving data, it will save the data in that locale.

Note that in case an entity has a _locale property set, that locale will win over the locale set via this method (and over the globally configured one for that matter)!

Parameters
$locale : string|null

The locale to use for fetching and saving records. Pass null in order to unset the current locale, and to make the behavior fall back to using the globally configured locale.

Return values
$this

translationField()

Returns a fully aliased field name for translated fields.

public translationField(string $field) : string

If the requested field is configured as a translation field, field with an alias of a corresponding association is returned. Table-aliased field name is returned for all other fields.

Parameters
$field : string

Field name to be aliased.

Return values
string

        
On this page

Search results