protected function WebformElementBase::setConfigurationFormDefaultValueRecursive in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElementBase.php \Drupal\webform\Plugin\WebformElementBase::setConfigurationFormDefaultValueRecursive()
Set configuration webform default values recursively.
Parameters
array $form: A webform render array.
array $element_properties: The element's properties without hash prefix. Any property that is found in the webform will be populated and unset from $element_properties array.
Return value
bool TRUE is the webform has any inputs.
1 call to WebformElementBase::setConfigurationFormDefaultValueRecursive()
- WebformElementBase::buildConfigurationForm in src/
Plugin/ WebformElementBase.php - Form constructor.
File
- src/
Plugin/ WebformElementBase.php, line 3474
Class
- WebformElementBase
- Provides a base class for a webform element.
Namespace
Drupal\webform\PluginCode
protected function setConfigurationFormDefaultValueRecursive(array &$form, array &$element_properties) {
$has_input = FALSE;
foreach ($form as $property_name => &$property_element) {
// Skip all properties.
if (WebformElementHelper::property($property_name)) {
continue;
}
// Skip Entity reference element 'selection_settings'.
// @see \Drupal\webform\Plugin\WebformElement\WebformEntityReferenceTrait::form
// @todo Fix entity reference Ajax and move code WebformEntityReferenceTrait.
if (!empty($property_element['#tree']) && $property_name === 'selection_settings') {
unset($element_properties[$property_name]);
$property_element['#parents'] = [
'properties',
$property_name,
];
$has_input = TRUE;
continue;
}
// Determine if the property element is an input using the webform element
// manager.
// Note: #access is used to protect inputs and containers that should
// always be visible.
$is_input = $this->elementManager
->getElementInstance($property_element)
->isInput($property_element);
if ($is_input) {
if (array_key_exists($property_name, $element_properties)) {
// If this property exists, then set its default value.
$this
->setConfigurationFormDefaultValue($form, $element_properties, $property_element, $property_name);
$has_input = TRUE;
}
elseif (empty($form[$property_name]['#access'])) {
// Else completely remove the property element from the webform.
unset($form[$property_name]);
}
}
else {
// Recurse down this container and see if it's children have inputs.
$container_has_input = $this
->setConfigurationFormDefaultValueRecursive($property_element, $element_properties);
if ($container_has_input) {
$has_input = TRUE;
}
elseif (empty($form[$property_name]['#access'])) {
unset($form[$property_name]);
}
}
}
return $has_input;
}