public static function YamlFormElementHelper::applyTranslation in YAML Form 8
Apply translation to element.
IMPORTANT: This basically a modified version YamlFormElementHelper::merge() that initially only merge element properties and ignores sub-element.
Parameters
array $element: An element.
array $translation: An associative array of translated element properties.
1 call to YamlFormElementHelper::applyTranslation()
- YamlForm::initElementsRecursive in src/
Entity/ YamlForm.php - Initialize form elements into a flatten array.
File
- src/
Utility/ YamlFormElementHelper.php, line 241
Class
- YamlFormElementHelper
- Helper class form element methods.
Namespace
Drupal\yamlform\UtilityCode
public static function applyTranslation(array &$element, array $translation) {
foreach ($element as $key => &$value) {
// Make sure to only merge properties.
if (!Element::property($key) || empty($translation[$key])) {
continue;
}
$translation_value = $translation[$key];
if (gettype($value) !== gettype($translation_value)) {
continue;
}
if (is_array($value)) {
self::merge($value, $translation_value);
}
elseif (is_scalar($value)) {
$element[$key] = $translation_value;
}
}
}