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' => '', ]; - $menu_options = Menu::loadMultiple(); - foreach ($menu_options as $key => $menu) { - $menu_options[$key] = $menu->label(); - } - asort($menu_options); $form['displays']['page']['options']['link_properties']['menu_name'] = [ '#title' => $this->t('Menu'), '#type' => 'select', - '#options' => $menu_options, + '#options' => $this->getMenusAsOptions(), ]; $form['displays']['page']['options']['link_properties']['title'] = [ '#title' => $this->t('Link text'), @@ -1289,6 +1284,21 @@ public function createView(array $form, FormStateInterface $form_state) { return $view; } + /** + * Returns keyed array of menus. + * + * @return \Drupal\system\MenuInterface[] + * Keyed array of menu name and label. + */ + protected function getMenusAsOptions() { + $options = Menu::loadMultiple(); + foreach ($options as $key => $menu) { + $options[$key] = $menu->label(); + } + asort($options); + return $options; + } + } /** diff --git a/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php index 501d9226ee..88984dbd6c 100644 --- a/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php @@ -27,7 +27,7 @@ class DisplayPageWebTest extends ViewTestBase { * * @var array */ - public static $modules = ['menu_ui', 'block', 'views_ui']; + public static $modules = ['block', 'views_ui']; /** * {@inheritdoc} @@ -117,6 +117,7 @@ public function testPageDisplayMenu() { $menu_link = $this->cssSelect('nav.block-menu ul.menu a'); $this->assertEqual($menu_link[0]->getText(), 'Test menu link'); + $this->container->get('module_installer')->install(['menu_ui', 'menu_link_content']); // Update the menu link. $this->drupalPostForm("admin/structure/menu/link/views_view:views.test_page_display_menu.page_3/edit", [ 'title' => 'New title', diff --git a/core/modules/views/tests/src/Functional/Plugin/MenuLinkTest.php b/core/modules/views/tests/src/Functional/Plugin/MenuLinkTest.php index 77591b44dd..533b04e1d0 100644 --- a/core/modules/views/tests/src/Functional/Plugin/MenuLinkTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/MenuLinkTest.php @@ -24,7 +24,7 @@ class MenuLinkTest extends ViewTestBase { * * @var array */ - public static $modules = ['views', 'views_ui', 'user', 'node', 'menu_ui', 'block']; + public static $modules = ['views', 'views_ui', 'user', 'node', 'menu_link_content', 'block']; /** * A user with permission to administer views, menus and view content. @@ -41,7 +41,7 @@ protected function setUp($import_test_views = TRUE) { $this->enableViewsTestModule(); - $this->adminUser = $this->drupalCreateUser(['administer views', 'administer menu']); + $this->adminUser = $this->drupalCreateUser(['administer views']); $this->drupalPlaceBlock('system_menu_block:main'); $this->drupalCreateContentType(['type' => 'page']); } diff --git a/core/modules/views/tests/src/Kernel/Plugin/Display/ViewsMenuLinkTest.php b/core/modules/views/tests/src/Kernel/Plugin/Display/ViewsMenuLinkTest.php index a6776b585a..fb9463b9ae 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/Display/ViewsMenuLinkTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/Display/ViewsMenuLinkTest.php @@ -15,7 +15,6 @@ class ViewsMenuLinkTest extends ViewsKernelTestBase { * {@inheritdoc} */ public static $modules = [ - 'menu_ui', 'user', 'views', ]; diff --git a/core/modules/views_ui/tests/src/Functional/DisplayPathTest.php b/core/modules/views_ui/tests/src/Functional/DisplayPathTest.php index 2f007f193c..18a719e56d 100644 --- a/core/modules/views_ui/tests/src/Functional/DisplayPathTest.php +++ b/core/modules/views_ui/tests/src/Functional/DisplayPathTest.php @@ -22,11 +22,6 @@ protected function setUp($import_test_views = TRUE) { $this->placeBlock('page_title_block'); } - /** - * {@inheritdoc} - */ - public static $modules = ['menu_ui']; - /** * Views used by this test. * @@ -120,7 +115,6 @@ public function testDeleteWithNoPath() { * Tests the menu and tab option form. */ public function testMenuOptions() { - $this->container->get('module_installer')->install(['menu_ui']); $this->drupalGet('admin/structure/views/view/test_view'); // Add a new page display.