protected function WebformHandlerBase::setSettingsParentsRecursively in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformHandlerBase.php \Drupal\webform\Plugin\WebformHandlerBase::setSettingsParentsRecursively()
Set configuration settings parents.
This helper method looks looks for the handler default configuration keys within a form and set a matching element's #parents property to ['settings', '{element_key}']
Parameters
array $elements: An array of form elements.
Return value
array Form element with #parents set.
1 call to WebformHandlerBase::setSettingsParentsRecursively()
- WebformHandlerBase::setSettingsParents in src/
Plugin/ WebformHandlerBase.php - Set configuration settings parents.
File
- src/
Plugin/ WebformHandlerBase.php, line 689
Class
- WebformHandlerBase
- Provides a base class for a webform handler.
Namespace
Drupal\webform\PluginCode
protected function setSettingsParentsRecursively(array &$elements) {
$default_configuration = $this
->defaultConfiguration();
foreach ($elements as $element_key => &$element) {
// Only a form element can have #parents.
if (!WebformElementHelper::isElement($element, $element_key)) {
continue;
}
// If the element has #parents property assume that it has also been
// defined for all sub-elements.
if (isset($element['#parents'])) {
continue;
}
// Only set #parents when #element has…
// - Default configuration.
// - Is an input.
// - #default_value or #value (aka input).
// - Not a container with children.
if (array_key_exists($element_key, $default_configuration) && isset($element['#type']) && !WebformElementHelper::hasChildren($element)) {
$element['#parents'] = [
'settings',
$element_key,
];
}
else {
$this
->setSettingsParentsRecursively($element);
}
}
return $elements;
}