Commit 455428cb authored by alexpott's avatar alexpott

Issue #2318435 by dawehner, Gábor Hojtsy: Fixed Views menu items disappears when editing menu.

parent cdf77e49
......@@ -669,7 +669,7 @@ display:
type: tab
title: Files
description: ''
name: admin
menu_name: admin
weight: 0
context: ''
display_description: ''
......
......@@ -549,14 +549,14 @@ display:
type: 'default tab'
title: Content
description: ''
name: admin
menu_name: admin
weight: -10
context: ''
tab_options:
type: normal
title: Content
description: 'Find and manage content'
name: admin
menu_name: admin
weight: -10
field_langcode: '***CURRENT_LANGUAGE***'
field_langcode_add_to_query: null
......
......@@ -880,14 +880,14 @@ display:
type: 'default tab'
title: List
description: 'Find and manage people interacting with your site.'
name: admin
menu_name: admin
weight: -10
context: ''
tab_options:
type: normal
title: People
description: 'Manage user accounts, roles, and permissions.'
name: admin
menu_name: admin
weight: 0
defaults:
show_admin_links: false
......
......@@ -34,7 +34,7 @@ views.display.page:
weight:
type: integer
label: 'Weight'
name:
menu_name:
type: string
label: 'Menu name'
context:
......@@ -56,7 +56,7 @@ views.display.page:
weight:
type: integer
label: 'Weight'
name:
menu_name:
type: string
label: 'Menu name'
......
......@@ -132,14 +132,16 @@ public function getDescription() {
*/
public function updateLink(array $new_definition_values, $persist) {
$overrides = array_intersect_key($new_definition_values, $this->overrideAllowed);
// Update the definition.
$this->pluginDefinition = $overrides + $this->pluginDefinition;
if ($persist) {
$view = $this->loadView();
$display = &$view->storage->getDisplay($view->current_display);
// Just save the title to the original view.
$changed = FALSE;
foreach (array('title' => 'title', 'weight' => 'weight', 'menu' => 'name', 'description' => 'description') as $definition_key => $views_key) {
if ($display['display_options']['menu'][$views_key] != $new_definition_values[$definition_key]) {
$display['display_options']['menu'][$views_key] = $new_definition_values[$definition_key];
foreach ($new_definition_values as $key => $new_definition_value) {
if (isset($display['display_options']['menu'][$key]) && $display['display_options']['menu'][$key] != $new_definition_values[$key]) {
$display['display_options']['menu'][$key] = $new_definition_values[$key];
$changed = TRUE;
}
}
......@@ -149,8 +151,6 @@ public function updateLink(array $new_definition_values, $persist) {
$view->storage->save();
}
}
// Update the definition.
$this->pluginDefinition = $overrides + $this->pluginDefinition;
return $this->pluginDefinition;
}
......
......@@ -50,7 +50,7 @@ protected function defineOptions() {
'title' => array('default' => '', 'translatable' => FALSE),
'description' => array('default' => '', 'translatable' => FALSE),
'weight' => array('default' => 0),
'name' => array('default' => 'navigation'),
'menu_name' => array('default' => 'navigation'),
'context' => array('default' => ''),
),
);
......@@ -61,7 +61,7 @@ protected function defineOptions() {
'title' => array('default' => '', 'translatable' => FALSE),
'description' => array('default' => '', 'translatable' => FALSE),
'weight' => array('default' => 0),
'name' => array('default' => 'navigation'),
'menu_name' => array('default' => 'navigation'),
),
);
......@@ -219,11 +219,11 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
// Only display the menu selector if Menu UI module is enabled.
if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
$form['menu']['name'] = array(
$form['menu']['menu_name'] = array(
'#title' => t('Menu'),
'#type' => 'select',
'#options' => menu_ui_get_menus(),
'#default_value' => $menu['name'],
'#default_value' => $menu['menu_name'],
'#states' => array(
'visible' => array(
array(
......@@ -237,9 +237,9 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
);
}
else {
$form['menu']['name'] = array(
$form['menu']['menu_name'] = array(
'#type' => 'value',
'#value' => $menu['name'],
'#value' => $menu['menu_name'],
);
$form['menu']['markup'] = array(
'#markup' => t('Menu selection requires the activation of Menu UI module.'),
......@@ -350,9 +350,9 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
);
}
else {
$form['tab_options']['name'] = array(
$form['tab_options']['menu_name'] = array(
'#type' => 'value',
'#value' => $tab_options['name'],
'#value' => $tab_options['menu_name'],
);
$form['tab_options']['markup'] = array(
'#markup' => t('Menu selection requires the activation of Menu UI module.'),
......
......@@ -314,7 +314,7 @@ public function getMenuLinks() {
}
// Insert item into the proper menu.
$links[$menu_link_id]['menu_name'] = $menu['name'];
$links[$menu_link_id]['menu_name'] = $menu['menu_name'];
// Keep track of where we came from.
$links[$menu_link_id]['metadata'] = array(
'view_id' => $view_id,
......
......@@ -1018,7 +1018,7 @@ protected function pageDisplayOptions(array $form, FormStateInterface $form_stat
if (!empty($page['link'])) {
$display_options['menu']['type'] = 'normal';
$display_options['menu']['title'] = $page['link_properties']['title'];
$display_options['menu']['name'] = $page['link_properties']['menu_name'];
$display_options['menu']['menu_name'] = $page['link_properties']['menu_name'];
}
return $display_options;
}
......
......@@ -21,6 +21,13 @@ class DisplayPageWebTest extends PluginTestBase {
*/
public static $testViews = array('test_page_display_arguments', 'test_page_display_menu');
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['menu_ui', 'block'];
protected function setUp() {
parent::setUp();
......@@ -73,6 +80,7 @@ public function testArguments() {
* Tests menu settings of page displays.
*/
public function testPageDisplayMenu() {
// Check local tasks.
$this->drupalGet('test_page_display_menu');
$this->assertResponse(200);
$element = $this->xpath('//ul[contains(@class, :ul_class)]//a[contains(@class, :a_class)]', array(
......@@ -93,6 +101,24 @@ public function testPageDisplayMenu() {
));
$this->assertEqual((string) $element[0], t('Test local tab'));
$this->assertTitle(t('Test local page | Drupal'));
// Check an ordinary menu link.
$admin_user = $this->drupalCreateUser(['administer menu']);
$this->drupalLogin($admin_user);
$this->drupalPlaceBlock('system_menu_block:tools');
$this->drupalGet('<front>');
$menu_link = $this->cssSelect('div.block-menu ul.menu a');
$this->assertEqual((string) $menu_link[0], 'Test menu link');
// Update the menu link.
$this->drupalPostForm("admin/structure/menu/link/views_view:views.test_page_display_menu.page_3/edit", [
'title' => 'New title',
], t('Save'));
$this->drupalGet('<front>');
$menu_link = $this->cssSelect('div.block-menu ul.menu a');
$this->assertEqual((string) $menu_link[0], 'New title');
}
}
......@@ -30,14 +30,14 @@ display:
type: 'default tab'
title: 'Test default tab'
description: ''
name: tools
menu_name: tools
weight: '-10'
context: '0'
tab_options:
type: normal
title: 'Test parent path'
description: ''
name: tools
menu_name: tools
weight: '0'
defaults:
title: '0'
......@@ -53,7 +53,7 @@ display:
type: tab
title: 'Test local tab'
description: ''
name: tools
menu_name: tools
weight: '0'
context: '0'
defaults:
......@@ -62,6 +62,23 @@ display:
display_title: Page
id: page_2
position: 0
page_3:
display_options:
path: test_page_display_menu_link
title: 'Test menu link'
menu:
type: normal
title: 'Test menu link'
description: ''
menu_name: tools
weight: '0'
context: '0'
defaults:
title: '0'
display_plugin: page
display_title: Page
id: page_3
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