CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 5.4 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.4
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
      • Association
      • Attribute
      • Behavior
        • Translate
      • Exception
      • Locator
      • Query
      • Rule
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Trait TranslateStrategyTrait

Contains common code needed by TranslateBehavior strategy classes.

Namespace: Cake\ORM\Behavior\Translate

Property Summary

  • $_config protected
    array<string, mixed>

    Runtime config

  • $_configInitialized protected
    bool

    Whether the config property has already been configured with defaults

  • $locale protected
    string|null

    The locale name that will be used to override fields in the bound table from the translations table

  • $table protected
    Cake\ORM\Table

    Table instance

  • $translationTable protected
    Cake\ORM\Table

    Instance of Table responsible for translating

Method Summary

  • _configDelete() protected

    Deletes a single config key.

  • _configRead() protected

    Reads a config key.

  • _configWrite() protected

    Writes a config key.

  • afterSave() public

    Unsets the temporary _i18n property after the entity has been saved

  • buildMarshalMap() public

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

  • configShallow() public

    Merge provided config with existing config. Unlike config() which does a recursive merge for nested keys, this method does a simple merge.

  • deleteConfig() public

    Deletes a config key.

  • getConfig() public

    Returns the config.

  • getConfigOrFail() public

    Returns the config for this specific key.

  • getLocale() public

    Returns the current locale.

  • getTranslationTable() public

    Return translation table instance.

  • setConfig() public

    Sets the config.

  • setLocale() public

    Sets the locale to be used.

  • unsetEmptyFields() protected

    Unset empty translations to avoid persistence.

Method Detail

_configDelete() ¶ protected

_configDelete(string $key): void

Deletes a single config key.

Parameters
string $key

Key to delete.

Returns
void
Throws
Cake\Core\Exception\CakeException
if attempting to clobber existing config

_configRead() ¶ protected

_configRead(string|null $key): $key is null ? array : mixed

Reads a config key.

Parameters
string|null $key

Key to read.

Returns
$key is null ? array : mixed

_configWrite() ¶ protected

_configWrite(array<string, mixed>|string $key, mixed $value, string|bool $merge = false): void

Writes a config key.

Parameters
array<string, mixed>|string $key

Key to write to.

mixed $value

Value to write.

string|bool $merge optional

True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.

Returns
void
Throws
Cake\Core\Exception\CakeException
if attempting to clobber existing config

afterSave() ¶ public

afterSave(Cake\Event\EventInterface<Cake\ORM\Table> $event, Cake\Datasource\EntityInterface $entity): void

Unsets the temporary _i18n property after the entity has been saved

Parameters
Cake\Event\EventInterface<Cake\ORM\Table> $event

The beforeSave event that was fired

Cake\Datasource\EntityInterface $entity

The entity that is going to be saved

Returns
void

buildMarshalMap() ¶ public

buildMarshalMap(Cake\ORM\Marshaller<Cake\Datasource\EntityInterface> $marshaller, array<string, callable> $map, array<string, mixed> $options): array<string, callable>

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

Add in _translations marshaling handlers. You can disable marshaling of translations by setting 'translations' => false in the options provided to Table::newEntity() or Table::patchEntity().

Parameters
Cake\ORM\Marshaller<Cake\Datasource\EntityInterface> $marshaller

The marshaler of the table the behavior is attached to.

array<string, callable> $map

The property map being built.

array<string, mixed> $options

The options array used in the marshaling call.

Returns
array<string, callable>

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

configShallow() ¶ public

configShallow(array<string, mixed>|string $key, mixed|null $value = null): $this

Merge provided config with existing config. Unlike config() which does a recursive merge for nested keys, this method does a simple merge.

Setting a specific value:

$this->configShallow('key', $value);

Setting a nested value:

$this->configShallow('some.nested.key', $value);

Updating multiple config settings at the same time:

$this->configShallow(['one' => 'value', 'another' => 'value']);
Parameters
array<string, mixed>|string $key

The key to set, or a complete array of configs.

mixed|null $value optional

The value to set.

Returns
$this

deleteConfig() ¶ public

deleteConfig(string $key): $this

Deletes a config key.

Parameters
string $key

Key to delete. It can be a dot separated string to delete nested keys.

Returns
$this

getConfig() ¶ public

getConfig(string|null $key = null, mixed $default = null): $key is null ? array : mixed

Returns the config.

Usage

Reading the whole config:

$this->getConfig();

Reading a specific value:

$this->getConfig('key');

Reading a nested value:

$this->getConfig('some.nested.key');

Reading with default value:

$this->getConfig('some-key', 'default-value');
Parameters
string|null $key optional

The key to get or null for the whole config.

mixed $default optional

The return value when the key does not exist.

Returns
$key is null ? array : mixed

Configuration data at the named key or null if the key does not exist.

getConfigOrFail() ¶ public

getConfigOrFail(string $key): mixed

Returns the config for this specific key.

The config value for this key must exist, it can never be null.

Parameters
string $key

The key to get.

Returns
mixed

Configuration data at the named key

Throws
InvalidArgumentException

getLocale() ¶ public

getLocale(): string

Returns the current locale.

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

Returns
string
See Also
\Cake\I18n\I18n::getLocale()
\Cake\ORM\Behavior\TranslateBehavior::setLocale()

getTranslationTable() ¶ public

getTranslationTable(): Cake\ORM\Table

Return translation table instance.

Returns
Cake\ORM\Table

setConfig() ¶ public

setConfig(array<string, mixed>|string $key, mixed|null $value = null, bool $merge = true): $this

Sets the config.

Usage

Setting a specific value:

$this->setConfig('key', $value);

Setting a nested value:

$this->setConfig('some.nested.key', $value);

Updating multiple config settings at the same time:

$this->setConfig(['one' => 'value', 'another' => 'value']);
Parameters
array<string, mixed>|string $key

The key to set, or a complete array of configs.

mixed|null $value optional

The value to set.

bool $merge optional

Whether to recursively merge or overwrite existing config, defaults to true.

Returns
$this
Throws
Cake\Core\Exception\CakeException
When trying to set a key that is invalid.

setLocale() ¶ public

setLocale(string|null $locale): $this

Sets the locale to be used.

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
string|null $locale

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

Returns
$this

unsetEmptyFields() ¶ protected

unsetEmptyFields(Cake\Datasource\EntityInterface $entity): void

Unset empty translations to avoid persistence.

Should only be called if $this->_config['allowEmptyTranslations'] is false.

Parameters
Cake\Datasource\EntityInterface $entity

The entity to check for empty translations fields inside.

Returns
void

Property Detail

$_config ¶ protected

Runtime config

Type
array<string, mixed>

$_configInitialized ¶ protected

Whether the config property has already been configured with defaults

Type
bool

$locale ¶ protected

The locale name that will be used to override fields in the bound table from the translations table

Type
string|null

$table ¶ protected

Table instance

Type
Cake\ORM\Table

$translationTable ¶ protected

Instance of Table responsible for translating

Type
Cake\ORM\Table
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs