public function buildMarshalMap($marshaller, $map, $options)
{
if (isset($options['translations']) && !$options['translations']) {
return [];
}
return ['_translations' => function ($value, $entity) use($marshaller, $options) {
$translations = $entity->get('_translations');
foreach ($this->_config['fields'] as $field) {
$options['validate'] = $this->_config['validator'];
$errors = [];
if (!is_array($value)) {
return;
}
foreach ($value as $language => $fields) {
if (!isset($translations[$language])) {
$translations[$language] = $this->_table->newEntity();
}
$marshaller->merge($translations[$language], $fields, $options);
if ((bool) $translations[$language]->errors()) {
$errors[$language] = $translations[$language]->errors();
}
}
// Set errors into the root entity, so validation errors
// match the original form data position.
$entity->errors($errors);
}
return $translations;
}];
}