protected function WebformEntitySettingsBaseForm::setElementDescriptionsRecursive in Webform 8.5
Same name and namespace in other branches
- 6.x src/EntitySettings/WebformEntitySettingsBaseForm.php \Drupal\webform\EntitySettings\WebformEntitySettingsBaseForm::setElementDescriptionsRecursive()
Append [none] message and default value to an element's description.
Parameters
array $form: An associative array containing the structure of the form.
array $default_settings: An associative array container default webform settings.
1 call to WebformEntitySettingsBaseForm::setElementDescriptionsRecursive()
- WebformEntitySettingsBaseForm::form in src/
EntitySettings/ WebformEntitySettingsBaseForm.php - Gets the actual form array to be built.
File
- src/
EntitySettings/ WebformEntitySettingsBaseForm.php, line 72
Class
- WebformEntitySettingsBaseForm
- Base webform entity settings form.
Namespace
Drupal\webform\EntitySettingsCode
protected function setElementDescriptionsRecursive(array &$form, array $default_settings) {
foreach ($form as $key => &$element) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
if (isset($element['#type']) && !empty($default_settings["default_{$key}"]) && empty($element['#disabled'])) {
if (!isset($element['#description'])) {
$element['#description'] = '';
}
// Append default value to an element's description.
$value = $default_settings["default_{$key}"];
if (!is_array($value)) {
if (isset($element['#options'])) {
$flattened_options = OptGroup::flattenOptions($element['#options']);
if (isset($flattened_options[$value])) {
$value = $flattened_options[$value];
}
}
$element['#description'] .= $element['#description'] ? '<br /><br />' : '';
$element['#description'] .= $this
->t('Defaults to: %value', [
'%value' => $value,
]);
}
// Append [none] message to an element's description.
if (preg_match('/_message$/', $key)) {
$none_translated = (string) $this
->t('[none]');
$element['#description'] .= $element['#description'] ? ' ' : '';
$t_args = [
'@none' => '[none]',
'@none_translated' => $none_translated,
];
if ('[none]' === $none_translated) {
$element['#description'] .= $this
->t('Enter @none to hide this message.', $t_args);
}
else {
$element['#description'] .= $this
->t('Enter @none or @none_translated to hide this message.', $t_args);
}
}
}
$this
->setElementDescriptionsRecursive($element, $default_settings);
}
}