public function MetatagsFieldProcessor::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 DefaultFieldProcessor::setTranslations
See also
\Drupal\tmgmt_content\Plugin\tmgmt\Source\ContentEntitySource::doSaveTranslations()
File
- sources/
content/ src/ MetatagsFieldProcessor.php, line 66
Class
- MetatagsFieldProcessor
- Field processor for the metatags field.
Namespace
Drupal\tmgmt_contentCode
public function setTranslations($field_data, FieldItemListInterface $field) {
$meta_tags_values = [];
// Loop over the groups and tags, either use the translated text or the
// original and then serialize the whole structure again.
foreach (Element::children($field_data) as $group_name) {
foreach (Element::children($field_data[$group_name]) as $tag_name) {
$property_data = $field_data[$group_name][$tag_name];
if (isset($property_data['#translation']['#text']) && $property_data['#translate']) {
$meta_tags_values[$tag_name] = $property_data['#translation']['#text'];
}
else {
$meta_tags_values[$tag_name] = $property_data['#text'];
}
}
}
$field->value = serialize($meta_tags_values);
}