public function DefaultFieldProcessor::setTranslations in Translation Management Tool 8
Process the translated data for this field back into a structure that can be saved by the content entity.
Parameters
array $field_data: The translated data for this field.
\Drupal\Core\Field\FieldItemListInterface $field: The field object.
Overrides FieldProcessorInterface::setTranslations
See also
\Drupal\tmgmt_content\Plugin\tmgmt\Source\ContentEntitySource::doSaveTranslations()
1 method overrides DefaultFieldProcessor::setTranslations()
- MetatagsFieldProcessor::setTranslations in sources/
content/ src/ MetatagsFieldProcessor.php - Process the translated data for this field back into a structure that can be saved by the content entity.
File
- sources/
content/ src/ DefaultFieldProcessor.php, line 82
Class
- DefaultFieldProcessor
- Default field processor.
Namespace
Drupal\tmgmt_contentCode
public function setTranslations($field_data, FieldItemListInterface $field) {
foreach (Element::children($field_data) as $delta) {
$field_item = $field_data[$delta];
foreach (Element::children($field_item) as $property) {
$property_data = $field_item[$property];
// If there is translation data for the field property, save it.
if (isset($property_data['#translation']['#text']) && $property_data['#translate']) {
// If the offset does not exist, populate it with the current value
// from the source content, so that the translated field offset can be
// saved.
if (!$field
->offsetExists($delta)) {
$translation = $field
->getEntity();
$source = $translation
->getUntranslated();
$source_field = $source
->get($field
->getName());
$source_offset = $source_field
->offsetGet($delta);
// Note that the source language value will be immediately
// overwritten.
$field
->offsetSet($delta, $source_offset);
}
$field
->offsetGet($delta)
->set($property, $property_data['#translation']['#text']);
}
}
}
}