protected function WebformTranslationManager::removeUnTranslatablePropertiesFromElement in Webform 8.5
Same name and namespace in other branches
- 6.x src/WebformTranslationManager.php \Drupal\webform\WebformTranslationManager::removeUnTranslatablePropertiesFromElement()
Remove untranslatable properties form an element.
Parameters
array $element: An element.
1 call to WebformTranslationManager::removeUnTranslatablePropertiesFromElement()
- WebformTranslationManager::getBaseElements in src/
WebformTranslationManager.php - Get base webform elements for the site's default language.
File
- src/
WebformTranslationManager.php, line 210
Class
- WebformTranslationManager
- Defines a class to translate webform elements.
Namespace
Drupal\webformCode
protected function removeUnTranslatablePropertiesFromElement(array &$element) {
$translatable_properties = $this
->getTranslatableProperties();
$element_plugin = $this->elementManager
->getElementInstance($element);
foreach ($element as $property_key => $property_value) {
$translatable_property_key = $property_key;
// If translatable property key is a sub element (ex: subelement__title)
// get the sub element's translatable property key.
if (preg_match('/^.*__(.*)$/', $translatable_property_key, $match)) {
$translatable_property_key = '#' . $match[1];
}
if (in_array($translatable_property_key, [
'#options',
'#answers',
]) && is_string($property_value)) {
// Unset options and answers that are webform option ids.
unset($element[$property_key]);
}
elseif ($translatable_property_key === '#element' && $element_plugin instanceof WebformCustomComposite) {
foreach ($element[$property_key] as &$composite_element_value) {
$this
->removeUnTranslatablePropertiesFromElement($composite_element_value);
}
}
elseif (!isset($translatable_properties[$translatable_property_key])) {
// Unset none translatable properties.
unset($element[$property_key]);
}
}
}