Cake\ORM\Behavior\TranslateBehavior::_rowMapper PHP Method

_rowMapper() protected method

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
return Cake\Collection\Collection
    protected function _rowMapper($results, $locale)
    {
        return $results->map(function ($row) use($locale) {
            if ($row === null) {
                return $row;
            }
            $hydrated = !is_array($row);
            foreach ($this->_config['fields'] as $field) {
                $name = $field . '_translation';
                $translation = isset($row[$name]) ? $row[$name] : null;
                if ($translation === null || $translation === false) {
                    unset($row[$name]);
                    continue;
                }
                $content = isset($translation['content']) ? $translation['content'] : null;
                if ($content !== null) {
                    $row[$field] = $content;
                }
                unset($row[$name]);
            }
            $row['_locale'] = $locale;
            if ($hydrated) {
                $row->clean();
            }
            return $row;
        });
    }