diff --git a/core/modules/views/src/Plugin/views/display/Page.php b/core/modules/views/src/Plugin/views/display/Page.php index 23409ec56d..12408f83d2 100644 --- a/core/modules/views/src/Plugin/views/display/Page.php +++ b/core/modules/views/src/Plugin/views/display/Page.php @@ -5,6 +5,7 @@ use Drupal\Component\Utility\Xss; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Menu\MenuParentFormSelectorInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\Routing\RouteProviderInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -49,6 +50,13 @@ class Page extends PathPluginBase { */ protected $menuStorage; + /** + * The parent form selector service. + * + * @var \Drupal\Core\Menu\MenuParentFormSelectorInterface + */ + protected $parentMenuSelector; + /** * Constructs a Page object. * @@ -64,10 +72,13 @@ class Page extends PathPluginBase { * The state key value store. * @param \Drupal\Core\Entity\EntityStorageInterface $menu_storage * The menu storage. + * @param \Drupal\Core\Menu\MenuParentFormSelectorInterface $parent_menu_selector + * The parent form selector service. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, StateInterface $state, EntityStorageInterface $menu_storage) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, StateInterface $state, EntityStorageInterface $menu_storage, MenuParentFormSelectorInterface $parent_menu_selector) { parent::__construct($configuration, $plugin_id, $plugin_definition, $route_provider, $state); $this->menuStorage = $menu_storage; + $this->parentMenuSelector = $parent_menu_selector; } /** @@ -80,7 +91,8 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_definition, $container->get('router.route_provider'), $container->get('state'), - $container->get('entity.manager')->getStorage('menu') + $container->get('entity_type.manager')->getStorage('menu'), + $container->get('menu.parent_form_selector') ); } @@ -311,34 +323,23 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { // Only display the parent selector if Menu UI module is enabled. $menu_parent = $menu['menu_name'] . ':' . $menu['parent']; - if (\Drupal::moduleHandler()->moduleExists('menu_ui')) { - $menu_link = 'views_view:views.' . $form_state->get('view')->id() . '.' . $form_state->get('display_id'); - $form['menu']['parent'] = \Drupal::service('menu.parent_form_selector')->parentSelectElement($menu_parent, $menu_link); - $form['menu']['parent'] += [ - '#title' => $this->t('Parent'), - '#description' => $this->t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.'), - '#attributes' => ['class' => ['menu-title-select']], - '#states' => [ - 'visible' => [ - [ - ':input[name="menu[type]"]' => ['value' => 'normal'], - ], - [ - ':input[name="menu[type]"]' => ['value' => 'tab'], - ], + $menu_link = 'views_view:views.' . $form_state->get('view')->id() . '.' . $form_state->get('display_id'); + $form['menu']['parent'] = $this->parentMenuSelector->parentSelectElement($menu_parent, $menu_link); + $form['menu']['parent'] += [ + '#title' => $this->t('Parent'), + '#description' => $this->t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.'), + '#attributes' => ['class' => ['menu-title-select']], + '#states' => [ + 'visible' => [ + [ + ':input[name="menu[type]"]' => ['value' => 'normal'], + ], + [ + ':input[name="menu[type]"]' => ['value' => 'tab'], ], ], - ]; - } - else { - $form['menu']['parent'] = [ - '#type' => 'value', - '#value' => $menu_parent, - ]; - $form['menu']['markup'] = [ - '#markup' => $this->t('Menu selection requires the activation of Menu UI module.'), - ]; - } + ], + ]; $form['menu']['weight'] = [ '#title' => $this->t('Weight'), '#type' => 'textfield', diff --git a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php index a3f3f696f0..1b12c03b53 100644 --- a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php +++ b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php @@ -308,15 +308,10 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#prefix' => '