Skip to content
Snippets Groups Projects

Issue #3238246: Support multivalue checkboxes attribute elements

1 file
+ 9
2
Compare changes
  • Side-by-side
  • Inline
+ 9
2
@@ -111,12 +111,19 @@ function menu_link_attributes_form_menu_link_content_form_alter(array &$form, Fo
'#default_value' => $menu_link_options[$attributes_key][$attribute_formatted] ?? ($info['default_value'] ?? ''),
];
// Fill options if select list.
if ($type == 'select') {
// Fill options for types that use it.
if (in_array($type, ['select', 'checkboxes', 'radios'], TRUE)) {
$form['options']['attributes'][$attribute]['#empty_option'] = t('- Select -');
$form['options']['attributes'][$attribute]['#options'] = $info['options'];
}
// Handle multivalue types.
if (in_array($type, ['checkboxes'], TRUE) && is_scalar($form['options']['attributes'][$attribute]['#default_value'])) {
// Reverse what \Drupal\Core\Template\AttributeArray::__toString() does.
$array = array_filter(explode(' ', $form['options']['attributes'][$attribute]['#default_value']));
$form['options']['attributes'][$attribute]['#default_value'] = $array;
}
// Fill options if type is "managed_file".
if ($type === 'managed_file' && !empty($info['upload_location'])) {
$form['options']['attributes'][$attribute]['#upload_location'] = $info['upload_location'];
Loading