Cake\ORM\Behavior\TranslateBehavior::_bundleTranslatedFields PHP Метод

_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
    protected function _bundleTranslatedFields($entity)
    {
        $translations = (array) $entity->get('_translations');
        if (empty($translations) && !$entity->dirty('_translations')) {
            return;
        }
        $fields = $this->_config['fields'];
        $primaryKey = (array) $this->_table->primaryKey();
        $key = $entity->get(current($primaryKey));
        $find = [];
        foreach ($translations as $lang => $translation) {
            foreach ($fields as $field) {
                if (!$translation->dirty($field)) {
                    continue;
                }
                $find[] = ['locale' => $lang, 'field' => $field, 'foreign_key' => $key];
                $contents[] = new Entity(['content' => $translation->get($field)], ['useSetters' => false]);
            }
        }
        if (empty($find)) {
            return;
        }
        $results = $this->_findExistingTranslations($find);
        foreach ($find as $i => $translation) {
            if (!empty($results[$i])) {
                $contents[$i]->set('id', $results[$i], ['setter' => false]);
                $contents[$i]->isNew(false);
            } else {
                $translation['model'] = $this->_config['referenceName'];
                $contents[$i]->set($translation, ['setter' => false, 'guard' => false]);
                $contents[$i]->isNew(true);
            }
        }
        $entity->set('_i18n', $contents);
    }