Issue #2202493 by Xano, dawehner, longwave, tim.plunkett: Fixed views_menu_link_defaults() does not set a parent for links.
parent
93beccc571
commit
ce842f8809
|
@ -51,6 +51,7 @@ class Page extends PathPluginBase {
|
|||
'description' => array('default' => '', 'translatable' => FALSE),
|
||||
'weight' => array('default' => 0),
|
||||
'menu_name' => array('default' => 'navigation'),
|
||||
'parent' => array('default' => ''),
|
||||
'context' => array('default' => ''),
|
||||
),
|
||||
);
|
||||
|
@ -217,13 +218,14 @@ class Page extends PathPluginBase {
|
|||
),
|
||||
);
|
||||
|
||||
// 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 @@ class Page extends PathPluginBase {
|
|||
);
|
||||
}
|
||||
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 @@ class Page extends PathPluginBase {
|
|||
|
||||
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 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
|
|||
);
|
||||
$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 @@ class DisplayPageTest extends ViewUnitTestBase {
|
|||
$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: ''
|
||||
|
|
Loading…
Reference in New Issue