Problem/Motivation
I was unsetting a radio element option in a formAlter in a custom webform handler, like this:
unset($form['elements']['my_radio_select']['#options']['5']);
An error occurred in webform.module::webform_process_options()
Steps to reproduce
The error occurs on the $title = (string) $element[$key]['#title']; line.
Sure, I fixed it by also unsetting the dynamically created child form element:
unset($form['elements']['my_radio_select']['#options']['5']);
unset($form['elements']['my_radio_select']['5']);
However, I think the code could be updated to verify that #title exists before accessing it, since custom modules/code might not know about the dynamically-created child element and that it needs to be unset, or about the automatically added #options_description_display default value if they aren't using it.
function webform_process_options(&$element, FormStateInterface $form_state, &$complete_form) {
if (!WebformElementHelper::isWebformElement($element)) {
return $element;
}
// Set #webform_element for all options (checkboxes and radios).
foreach (Element::children($element) as $key) {
$element[$key]['#webform_element'] = TRUE;
}
// Description display.
if (!empty($element['#options_description_display'])) {
$description_property_name = ($element['#options_description_display'] === 'help') ? '#help' : '#description';
foreach (Element::children($element) as $key) {
$title = (string) $element[$key]['#title'];
// Check for -- delimiter.
if (!WebformOptionsHelper::hasOptionDescription($title)) {
continue;
}
[$title, $description] = WebformOptionsHelper::splitOption($title);
$element[$key]['#title'] = $title;
$element[$key][$description_property_name] = $description;
}
}
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork webform-3614927
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments