Skip to content
Snippets Groups Projects

Issue #3490844: Inherit default values of menu_ui

1 file
+ 16
2
Compare changes
  • Side-by-side
  • Inline
@@ -273,8 +273,10 @@ function menu_ui_async_widget_form_node_type_form_alter(&$form, FormStateInterfa
return $menu->label();
}, Menu::loadMultiple());
asort($menu_options);
/** @var \Drupal\node\NodeTypeInterface $type */
$type = $form_state->getFormObject()->getEntity();
$form['menu_async'] = [
'#type' => 'details',
'#title' => t('Menu UI Async settings'),
@@ -283,13 +285,19 @@ function menu_ui_async_widget_form_node_type_form_alter(&$form, FormStateInterfa
],
'#group' => 'additional_settings',
];
// Inherit default menus values from default menu settings.
$default_menus = $type->getThirdPartySetting('menu_ui', 'available_menus', ['main']);
$default_menus_async = $type->getThirdPartySetting('menu_ui_async_widget', 'available_menus', $default_menus);
$form['menu_async']['menu_async_options'] = [
'#type' => 'checkboxes',
'#title' => t('Available menus'),
'#default_value' => $type->getThirdPartySetting('menu_ui_async_widget', 'available_menus', ['main']),
'#default_value' => $default_menus_async,
'#options' => $menu_options,
'#description' => t('The menus available to place links in for this content type.'),
];
// @todo See if we can avoid pre-loading all options by changing the form or
// using a #process callback. https://www.drupal.org/node/2310319
// To avoid an 'illegal option' error after saving the form we have to load
@@ -297,14 +305,20 @@ function menu_ui_async_widget_form_node_type_form_alter(&$form, FormStateInterfa
// add options to the list using ajax.
$options_cacheability = new CacheableMetadata();
$options = $menu_parent_selector->getParentSelectOptions('', NULL, $options_cacheability);
// Inherit selected parent menu item from default menu settings.
$default_menu_item = $type->getThirdPartySetting('menu_ui', 'parent', 'main:');
$default_menu_item_async = $type->getThirdPartySetting('menu_ui_async_widget', 'parent', $default_menu_item);
$form['menu_async']['menu_async_parent'] = [
'#type' => 'select',
'#title' => t('Default parent link'),
'#default_value' => $type->getThirdPartySetting('menu_ui_async_widget', 'parent', 'main:'),
'#default_value' => $default_menu_item_async,
'#options' => $options,
'#description' => t('Choose the menu link to be the default parent for a new link in the content authoring form.'),
'#attributes' => ['class' => ['menu-title-select']],
];
$options_cacheability->applyTo($form['menu_async']['menu_async_parent']);
$form['#validate'][] = 'menu_ui_async_widget_form_node_type_form_validate';
Loading