function entity_translation_form_element_language_replace in Entity Translation 7
Helper function. Recursively replaces the source language with the given one.
1 call to entity_translation_form_element_language_replace()
- entity_translation_prepare_element in ./
entity_translation.module - Form element process callback.
File
- ./
entity_translation.module, line 1372
Code
function entity_translation_form_element_language_replace(&$element, $source, $langcode) {
$element_children = element_children($element);
// PHP >= 7.4 compatibility fix till #3165377 lands.
$element_properties = array_diff(array_keys($element), $element_children);
// Iterate through the form structure recursively.
foreach ($element_children as $key) {
entity_translation_form_element_language_replace($element[$key], $source, $langcode);
}
// Replace specific occurrences of the source language with the target
// language.
foreach ($element_properties as $key) {
if ($key === '#language' && $element[$key] != LANGUAGE_NONE) {
$element[$key] = $langcode;
}
elseif ($key === '#parents' || $key === '#field_parents') {
foreach ($element[$key] as $delta => $value) {
if ($value === $source) {
$element[$key][$delta] = $langcode;
}
}
}
elseif ($key === '#limit_validation_errors') {
foreach ($element[$key] as $section => $section_value) {
foreach ($element[$key][$section] as $delta => $value) {
if ($value === $source) {
$element[$key][$section][$delta] = $langcode;
}
}
}
}
}
}