Commit ce842f88 authored by alexpott's avatar alexpott

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
......@@ -51,6 +51,7 @@ protected function defineOptions() {
'description' => array('default' => '', 'translatable' => FALSE),
'weight' => array('default' => 0),
'menu_name' => array('default' => 'navigation'),
'parent' => array('default' => ''),
'context' => array('default' => ''),
),
);
......@@ -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')) {
$form['menu']['menu_name'] = array(
'#title' => t('Menu'),
'#type' => 'select',
'#options' => menu_ui_get_menus(),
'#default_value' => $menu['menu_name'],
$form['menu']['parent'] = \Drupal::service('menu.parent_form_selector')->parentSelectElement($menu_parent);
$form['menu']['parent'] += array(
'#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' => array('class' => array('menu-title-select')),
'#states' => array(
'visible' => array(
array(
......@@ -237,9 +239,9 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
);
}
else {
$form['menu']['menu_name'] = array(
$form['menu']['parent'] = array(
'#type' => 'value',
'#value' => $menu['menu_name'],
'#value' => $menu_parent,
);
$form['menu']['markup'] = array(
'#markup' => t('Menu selection requires the activation of Menu UI module.'),
......@@ -410,7 +412,9 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) {
switch ($form_state['section']) {
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.
if ($form_state->getValue(array('menu', 'type')) == 'default tab') {
$form_state['view']->addFormToStack('display', $this->display['id'], 'tab_options');
......
......@@ -308,6 +308,7 @@ public function getMenuLinks() {
);
$links[$menu_link_id]['title'] = $menu['title'];
$links[$menu_link_id]['description'] = $menu['description'];
$links[$menu_link_id]['parent'] = $menu['parent'];
if (isset($menu['weight'])) {
$links[$menu_link_id]['weight'] = intval($menu['weight']);
......
......@@ -7,9 +7,11 @@
namespace Drupal\views\Tests\Plugin;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\views\Views;
use Drupal\views\Tests\ViewUnitTestBase;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
......@@ -26,7 +28,7 @@ class DisplayPageTest extends ViewUnitTestBase {
*
* @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.
......@@ -127,4 +129,15 @@ public function testPageRouterItems() {
$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:
display_title: Page
id: page_3
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'
id: test_page_display_menu
tag: ''
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment