Handles adjusting the field item data if a format was detected.
string $format: The text format.
array $data: The extracted field data.
int $delta: The field item delta.
array The adjusted field data.
protected function handleFormat($format, $data, $delta) {
$allowed_formats = (array) \Drupal::config('tmgmt.settings')
->get('allowed_formats');
if ($allowed_formats && array_search($format, $allowed_formats) === FALSE) {
// There are allowed formats and this one is not part of them,
// explicitly mark all data as untranslatable.
foreach ($data[$delta] as $name => $value) {
if (is_array($value) && isset($value['#translate'])) {
$data[$delta][$name]['#translate'] = FALSE;
}
}
}
else {
// Add the format to the translatable properties.
foreach ($data[$delta] as $name => $value) {
if (is_array($value) && isset($value['#translate']) && $value['#translate'] == TRUE) {
$data[$delta][$name]['#format'] = $format;
}
}
}
return $data;
}