Revert "Issue #2468713 by StryKaizer, jhedstrom, rootwork, dawehner, paulmckibben: Internal/custom menu links force-reset to the top of their menus on cache rebuild"
This reverts commit 5cd3b6852e
.
8.0.x
parent
5cd3b6852e
commit
6374e3041e
|
@ -157,9 +157,6 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
|
||||||
foreach ($definitions as $id => $link) {
|
foreach ($definitions as $id => $link) {
|
||||||
// Flag this link as discovered, i.e. saved via rebuild().
|
// Flag this link as discovered, i.e. saved via rebuild().
|
||||||
$link['discovered'] = 1;
|
$link['discovered'] = 1;
|
||||||
// Note: The parent we set here might be just stored in the {menu_tree}
|
|
||||||
// table, so it will not end up in $top_links. Therefore the later loop
|
|
||||||
// on the orphan links, will handle those cases.
|
|
||||||
if (!empty($link['parent'])) {
|
if (!empty($link['parent'])) {
|
||||||
$children[$link['parent']][$id] = $id;
|
$children[$link['parent']][$id] = $id;
|
||||||
}
|
}
|
||||||
|
@ -177,18 +174,8 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
|
||||||
// Handle any children we didn't find starting from top-level links.
|
// Handle any children we didn't find starting from top-level links.
|
||||||
foreach ($children as $orphan_links) {
|
foreach ($children as $orphan_links) {
|
||||||
foreach ($orphan_links as $id) {
|
foreach ($orphan_links as $id) {
|
||||||
// Check for a parent that is not loaded above since only internal links
|
// Force it to the top level.
|
||||||
// are loaded above.
|
$links[$id]['parent'] = '';
|
||||||
$parent = $this->loadFull($links[$id]['parent']);
|
|
||||||
// If there is a parent add it to the links to be used in
|
|
||||||
// ::saveRecursive().
|
|
||||||
if ($parent) {
|
|
||||||
$links[$links[$id]['parent']] = $parent;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Force it to the top level.
|
|
||||||
$links[$id]['parent'] = '';
|
|
||||||
}
|
|
||||||
$this->saveRecursive($id, $children, $links);
|
$this->saveRecursive($id, $children, $links);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -319,37 +319,6 @@ class MenuTreeStorageTest extends KernelTestBase {
|
||||||
$this->assertEqual($this->treeStorage->getSubtreeHeight('child4'), 1);
|
$this->assertEqual($this->treeStorage->getSubtreeHeight('child4'), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensure hierarchy persists after a menu rebuild.
|
|
||||||
*/
|
|
||||||
public function testMenuRebuild() {
|
|
||||||
// root
|
|
||||||
// - child1
|
|
||||||
// -- child2
|
|
||||||
// --- child3
|
|
||||||
// ---- child4
|
|
||||||
$this->addMenuLink('root');
|
|
||||||
$this->addMenuLink('child1', 'root');
|
|
||||||
$this->addMenuLink('child2', 'child1');
|
|
||||||
$this->addMenuLink('child3', 'child2');
|
|
||||||
$this->addMenuLink('child4', 'child3');
|
|
||||||
|
|
||||||
$this->assertEqual($this->treeStorage->getSubtreeHeight('root'), 5);
|
|
||||||
$this->assertEqual($this->treeStorage->getSubtreeHeight('child1'), 4);
|
|
||||||
$this->assertEqual($this->treeStorage->getSubtreeHeight('child2'), 3);
|
|
||||||
$this->assertEqual($this->treeStorage->getSubtreeHeight('child3'), 2);
|
|
||||||
$this->assertEqual($this->treeStorage->getSubtreeHeight('child4'), 1);
|
|
||||||
|
|
||||||
// Intentionally leave child3 out to mimic static or external links.
|
|
||||||
$definitions = $this->treeStorage->loadMultiple(['root', 'child1', 'child2', 'child4']);
|
|
||||||
$this->treeStorage->rebuild($definitions);
|
|
||||||
$this->assertEqual($this->treeStorage->getSubtreeHeight('root'), 5);
|
|
||||||
$this->assertEqual($this->treeStorage->getSubtreeHeight('child1'), 4);
|
|
||||||
$this->assertEqual($this->treeStorage->getSubtreeHeight('child2'), 3);
|
|
||||||
$this->assertEqual($this->treeStorage->getSubtreeHeight('child3'), 2);
|
|
||||||
$this->assertEqual($this->treeStorage->getSubtreeHeight('child4'), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests MenuTreeStorage::loadByProperties().
|
* Tests MenuTreeStorage::loadByProperties().
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,102 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* Contains \Drupal\views\Tests\Plugin\MenuLinkTest.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Drupal\views\Tests\Plugin;
|
|
||||||
|
|
||||||
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
|
||||||
use Drupal\views\Tests\ViewTestBase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the menu links created in views.
|
|
||||||
*
|
|
||||||
* @group views
|
|
||||||
*/
|
|
||||||
class MenuLinkTest extends ViewTestBase {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Views used by this test.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $testViews = ['test_menu_link'];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modules to enable.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $modules = ['views', 'views_ui', 'user', 'node', 'menu_ui', 'block'];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A user with permission to administer views, menus and view content.
|
|
||||||
*
|
|
||||||
* @var \Drupal\user\UserInterface
|
|
||||||
*/
|
|
||||||
protected $adminUser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function setUp() {
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$this->enableViewsTestModule();
|
|
||||||
|
|
||||||
$this->adminUser = $this->drupalCreateUser(['administer views', 'administer menu']);
|
|
||||||
$this->drupalPlaceBlock('system_menu_block:main');
|
|
||||||
$this->drupalCreateContentType(['type' => 'page']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that menu links using menu_link_content as parent are visible.
|
|
||||||
*/
|
|
||||||
public function testHierarchicalMenuLinkVisibility() {
|
|
||||||
$this->drupalLogin($this->adminUser);
|
|
||||||
|
|
||||||
$node = $this->drupalCreateNode(['type' => 'page']);
|
|
||||||
|
|
||||||
// Create a primary level menu link to the node.
|
|
||||||
$link = MenuLinkContent::create([
|
|
||||||
'title' => 'Primary level node',
|
|
||||||
'menu_name' => 'main',
|
|
||||||
'bundle' => 'menu_link_content',
|
|
||||||
'parent' => '',
|
|
||||||
'link' => [['uri' => 'entity:node/' . $node->id()]],
|
|
||||||
]);
|
|
||||||
$link->save();
|
|
||||||
|
|
||||||
$parent_menu_value = 'main:menu_link_content:' . $link->uuid();
|
|
||||||
|
|
||||||
// Alter the view's menu link in view page to use the menu link from the
|
|
||||||
// node as parent.
|
|
||||||
$this->drupalPostForm("admin/structure/views/nojs/display/test_menu_link/page_1/menu", [
|
|
||||||
'menu[type]' => 'normal',
|
|
||||||
'menu[title]' => 'Secondary level view page',
|
|
||||||
'menu[parent]' => $parent_menu_value,
|
|
||||||
], 'Apply');
|
|
||||||
|
|
||||||
// Save view which has pending changes.
|
|
||||||
$this->drupalPostForm(NULL, [], 'Save');
|
|
||||||
|
|
||||||
// Test if the node as parent menu item is selected in our views settings.
|
|
||||||
$this->drupalGet('admin/structure/views/nojs/display/test_menu_link/page_1/menu');
|
|
||||||
$this->assertOptionSelected('edit-menu-parent', $parent_menu_value);
|
|
||||||
|
|
||||||
$this->drupalGet('');
|
|
||||||
|
|
||||||
// Test if the primary menu item (node) is visible, and the secondary menu
|
|
||||||
// item (view) is hidden.
|
|
||||||
$this->assertText('Primary level node');
|
|
||||||
$this->assertNoText('Secondary level view page');
|
|
||||||
|
|
||||||
// Go to the node page and ensure that both the first and second level items
|
|
||||||
// are visible.
|
|
||||||
$this->drupalGet($node->urlInfo());
|
|
||||||
$this->assertText('Primary level node');
|
|
||||||
$this->assertText('Secondary level view page');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
langcode: en
|
|
||||||
status: true
|
|
||||||
dependencies: { }
|
|
||||||
id: test_menu_link
|
|
||||||
label: ''
|
|
||||||
module: views
|
|
||||||
description: ''
|
|
||||||
tag: ''
|
|
||||||
base_table: views_test_data
|
|
||||||
base_field: nid
|
|
||||||
core: '8'
|
|
||||||
display:
|
|
||||||
default:
|
|
||||||
display_options:
|
|
||||||
defaults:
|
|
||||||
fields: false
|
|
||||||
pager: false
|
|
||||||
sorts: false
|
|
||||||
fields:
|
|
||||||
age:
|
|
||||||
field: age
|
|
||||||
id: age
|
|
||||||
relationship: none
|
|
||||||
table: views_test_data
|
|
||||||
plugin_id: numeric
|
|
||||||
display_plugin: default
|
|
||||||
display_title: Master
|
|
||||||
id: default
|
|
||||||
position: 0
|
|
||||||
page_1:
|
|
||||||
display_plugin: page
|
|
||||||
display_title: 'Test page view'
|
|
||||||
id: page_1
|
|
||||||
position: 1
|
|
||||||
display_options:
|
|
||||||
display_extenders: { }
|
|
||||||
path: test-menu-link
|
|
||||||
|
|
Loading…
Reference in New Issue