public function YamlFormTranslationManager::getBaseElements in YAML Form 8
Get base form elements from the site's default language.
Parameters
\Drupal\yamlform\YamlFormInterface $yamlform: A form.
Return value
array Base form elements as a flattened associative array.
Overrides YamlFormTranslationManagerInterface::getBaseElements
1 call to YamlFormTranslationManager::getBaseElements()
- YamlFormTranslationManager::getSourceElements in src/
YamlFormTranslationManager.php - Get flattened associative array of translated element properties.
File
- src/
YamlFormTranslationManager.php, line 76
Class
- YamlFormTranslationManager
- Defines a class to translate form elements.
Namespace
Drupal\yamlformCode
public function getBaseElements(YamlFormInterface $yamlform) {
$default_langcode = $this->languageManager
->getDefaultLanguage()
->getId();
$config_elements = $this
->getConfigElements($yamlform, $default_langcode);
$elements = YamlFormElementHelper::getFlattened($config_elements);
$translatable_properties = YamlFormArrayHelper::addPrefix($this->elementManager
->getTranslatableProperties());
foreach ($elements as $element_key => &$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 form option ids.
unset($element[$property_key]);
}
elseif (!isset($translatable_properties[$translatable_property_key])) {
// Unset none translatble properties.
unset($element[$property_key]);
}
}
if (empty($element)) {
unset($elements[$element_key]);
}
}
return $elements;
}