Skip to content
Snippets Groups Projects
Commit ce842f88 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2202493 by Xano, dawehner, longwave, tim.plunkett: Fixed...

Issue #2202493 by Xano, dawehner, longwave, tim.plunkett: Fixed views_menu_link_defaults() does not set a parent for links.
parent 93beccc5
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -51,6 +51,7 @@ protected function defineOptions() { ...@@ -51,6 +51,7 @@ protected function defineOptions() {
'description' => array('default' => '', 'translatable' => FALSE), 'description' => array('default' => '', 'translatable' => FALSE),
'weight' => array('default' => 0), 'weight' => array('default' => 0),
'menu_name' => array('default' => 'navigation'), 'menu_name' => array('default' => 'navigation'),
'parent' => array('default' => ''),
'context' => array('default' => ''), 'context' => array('default' => ''),
), ),
); );
...@@ -217,13 +218,14 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ...@@ -217,13 +218,14 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
), ),
); );
// Only display the menu selector if Menu UI module is enabled. // Only display the parent selector if Menu UI module is enabled.
$menu_parent = $menu['menu_name'] . ':' . $menu['parent'];
if (\Drupal::moduleHandler()->moduleExists('menu_ui')) { if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
$form['menu']['menu_name'] = array( $form['menu']['parent'] = \Drupal::service('menu.parent_form_selector')->parentSelectElement($menu_parent);
'#title' => t('Menu'), $form['menu']['parent'] += array(
'#type' => 'select', '#title' => $this->t('Parent'),
'#options' => menu_ui_get_menus(), '#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.'),
'#default_value' => $menu['menu_name'], '#attributes' => array('class' => array('menu-title-select')),
'#states' => array( '#states' => array(
'visible' => array( 'visible' => array(
array( array(
...@@ -237,9 +239,9 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ...@@ -237,9 +239,9 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
); );
} }
else { else {
$form['menu']['menu_name'] = array( $form['menu']['parent'] = array(
'#type' => 'value', '#type' => 'value',
'#value' => $menu['menu_name'], '#value' => $menu_parent,
); );
$form['menu']['markup'] = array( $form['menu']['markup'] = array(
'#markup' => t('Menu selection requires the activation of Menu UI module.'), '#markup' => t('Menu selection requires the activation of Menu UI module.'),
...@@ -410,7 +412,9 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) { ...@@ -410,7 +412,9 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) {
switch ($form_state['section']) { switch ($form_state['section']) {
case 'menu': case 'menu':
$this->setOption('menu', $form_state->getValue('menu')); $menu = $form_state->getValue('menu');
list($menu['menu_name'], $menu['parent']) = explode(':', $menu['parent'], 2);
$this->setOption('menu', $menu);
// send ajax form to options page if we use it. // send ajax form to options page if we use it.
if ($form_state->getValue(array('menu', 'type')) == 'default tab') { if ($form_state->getValue(array('menu', 'type')) == 'default tab') {
$form_state['view']->addFormToStack('display', $this->display['id'], 'tab_options'); $form_state['view']->addFormToStack('display', $this->display['id'], 'tab_options');
......
...@@ -308,6 +308,7 @@ public function getMenuLinks() { ...@@ -308,6 +308,7 @@ public function getMenuLinks() {
); );
$links[$menu_link_id]['title'] = $menu['title']; $links[$menu_link_id]['title'] = $menu['title'];
$links[$menu_link_id]['description'] = $menu['description']; $links[$menu_link_id]['description'] = $menu['description'];
$links[$menu_link_id]['parent'] = $menu['parent'];
if (isset($menu['weight'])) { if (isset($menu['weight'])) {
$links[$menu_link_id]['weight'] = intval($menu['weight']); $links[$menu_link_id]['weight'] = intval($menu['weight']);
......
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
namespace Drupal\views\Tests\Plugin; namespace Drupal\views\Tests\Plugin;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\Core\Session\AnonymousUserSession; use Drupal\Core\Session\AnonymousUserSession;
use Drupal\views\Views; use Drupal\views\Views;
use Drupal\views\Tests\ViewUnitTestBase; use Drupal\views\Tests\ViewUnitTestBase;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\HttpKernelInterface;
...@@ -26,7 +28,7 @@ class DisplayPageTest extends ViewUnitTestBase { ...@@ -26,7 +28,7 @@ class DisplayPageTest extends ViewUnitTestBase {
* *
* @var array * @var array
*/ */
public static $testViews = array('test_page_display', 'test_page_display_route'); public static $testViews = array('test_page_display', 'test_page_display_route', 'test_page_display_menu');
/** /**
* Modules to enable. * Modules to enable.
...@@ -127,4 +129,15 @@ public function testPageRouterItems() { ...@@ -127,4 +129,15 @@ public function testPageRouterItems() {
$this->assertFalse($route->hasDefault('arg_1'), 'No default value is set for the required argument id_2.'); $this->assertFalse($route->hasDefault('arg_1'), 'No default value is set for the required argument id_2.');
} }
/**
* Tests the generated menu links of views.
*/
public function testMenuLinks() {
\Drupal::service('plugin.manager.menu.link')->rebuild();
$tree = \Drupal::menuTree()->load('admin', new MenuTreeParameters());
$this->assertTrue(isset($tree['system.admin']->subtree['views_view:views.test_page_display_menu.page_4']));
$menu_link = $tree['system.admin']->subtree['views_view:views.test_page_display_menu.page_4']->link;
$this->assertEqual($menu_link->getTitle(), 'Test child');
}
} }
...@@ -79,6 +79,24 @@ display: ...@@ -79,6 +79,24 @@ display:
display_title: Page display_title: Page
id: page_3 id: page_3
position: 0 position: 0
page_4:
display_options:
path: test_page_display_menu/child
title: 'Test page as child'
menu:
type: normal
title: 'Test child'
parent: 'system.admin'
description: ''
name: tools
weight: '0'
context: '0'
defaults:
title: '0'
display_plugin: page
display_title: Page
id: page_4
position: 0
label: 'Test page menu' label: 'Test page menu'
id: test_page_display_menu id: test_page_display_menu
tag: '' tag: ''
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment