summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2016-06-21 14:15:32 +0100
committerAlex Pott2016-06-21 14:15:32 +0100
commitfa5294825ac6b724a15bae33261cb165d0cb8ea2 (patch)
tree2119dbb410afa27b38bd536c11687d63b07f2293
parent8ed14e0eaecbe5b384fc661a021cb027d0ee4b24 (diff)
Issue #2464077 by webflo, s_leu, dawehner, Lendude: Menu link overrides are lost after cache rebuild
-rw-r--r--core/modules/views/config/schema/views.display.schema.yml6
-rw-r--r--core/modules/views/src/Plugin/Menu/ViewsMenuLink.php7
-rw-r--r--core/modules/views/src/Plugin/views/display/Page.php1
-rw-r--r--core/modules/views/src/Plugin/views/display/PathPluginBase.php2
-rw-r--r--core/modules/views/tests/src/Kernel/Plugin/Display/ViewsMenuLinkTest.php98
-rw-r--r--core/modules/views/views.install22
6 files changed, 132 insertions, 4 deletions
diff --git a/core/modules/views/config/schema/views.display.schema.yml b/core/modules/views/config/schema/views.display.schema.yml
index 511b0b9..d17c48c 100644
--- a/core/modules/views/config/schema/views.display.schema.yml
+++ b/core/modules/views/config/schema/views.display.schema.yml
@@ -34,6 +34,12 @@ views.display.page:
weight:
type: integer
label: 'Weight'
+ enabled:
+ type: boolean
+ label: 'Enabled'
+ expanded:
+ type: boolean
+ label: 'Expanded'
menu_name:
type: string
label: 'Menu name'
diff --git a/core/modules/views/src/Plugin/Menu/ViewsMenuLink.php b/core/modules/views/src/Plugin/Menu/ViewsMenuLink.php
index 33a2fd2..b484c24 100644
--- a/core/modules/views/src/Plugin/Menu/ViewsMenuLink.php
+++ b/core/modules/views/src/Plugin/Menu/ViewsMenuLink.php
@@ -26,7 +26,6 @@ class ViewsMenuLink extends MenuLinkBase implements ContainerFactoryPluginInterf
'enabled' => 1,
'title' => 1,
'description' => 1,
- 'metadata' => 1,
);
/**
@@ -140,9 +139,9 @@ class ViewsMenuLink extends MenuLinkBase implements ContainerFactoryPluginInterf
$display = &$view->storage->getDisplay($view->current_display);
// Just save the title to the original view.
$changed = FALSE;
- 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];
+ foreach ($overrides as $key => $new_definition_value) {
+ if (empty($display['display_options']['menu'][$key]) || $display['display_options']['menu'][$key] != $new_definition_value) {
+ $display['display_options']['menu'][$key] = $new_definition_value;
$changed = TRUE;
}
}
diff --git a/core/modules/views/src/Plugin/views/display/Page.php b/core/modules/views/src/Plugin/views/display/Page.php
index a046698..d79b75b 100644
--- a/core/modules/views/src/Plugin/views/display/Page.php
+++ b/core/modules/views/src/Plugin/views/display/Page.php
@@ -124,6 +124,7 @@ class Page extends PathPluginBase {
'title' => array('default' => ''),
'description' => array('default' => ''),
'weight' => array('default' => 0),
+ 'enabled' => array('default' => TRUE),
'menu_name' => array('default' => 'main'),
'parent' => array('default' => ''),
'context' => array('default' => ''),
diff --git a/core/modules/views/src/Plugin/views/display/PathPluginBase.php b/core/modules/views/src/Plugin/views/display/PathPluginBase.php
index 9ee7fd2..966cc1a 100644
--- a/core/modules/views/src/Plugin/views/display/PathPluginBase.php
+++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php
@@ -322,6 +322,8 @@ 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'];
+ $links[$menu_link_id]['enabled'] = $menu['enabled'];
+ $links[$menu_link_id]['expanded'] = $menu['expanded'];
if (isset($menu['weight'])) {
$links[$menu_link_id]['weight'] = intval($menu['weight']);
diff --git a/core/modules/views/tests/src/Kernel/Plugin/Display/ViewsMenuLinkTest.php b/core/modules/views/tests/src/Kernel/Plugin/Display/ViewsMenuLinkTest.php
new file mode 100644
index 0000000..9e05ebc
--- /dev/null
+++ b/core/modules/views/tests/src/Kernel/Plugin/Display/ViewsMenuLinkTest.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace Drupal\Tests\views\Kernel\Plugin\Display;
+
+use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
+
+/**
+ * Menu link test.
+ *
+ * @group views
+ */
+class ViewsMenuLinkTest extends ViewsKernelTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = [
+ 'menu_ui',
+ 'user',
+ 'views'
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $testViews = ['test_page_display_menu'];
+
+ /**
+ * The entity manager.
+ *
+ * @var \Drupal\Core\Entity\EntityManagerInterface
+ */
+ protected $entityManger;
+
+ /**
+ * The menu link manager.
+ *
+ * @var \Drupal\Core\Menu\MenuLinkManagerInterface
+ */
+ protected $menuLinkManager;
+
+ /**
+ * The menu link overrides.
+ *
+ * @var \Drupal\Core\Menu\StaticMenuLinkOverridesInterface
+ */
+ protected $menuLinkOverrides;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp($import_test_views = TRUE) {
+ parent::setUp($import_test_views);
+
+ $this->entityManger = $this->container->get('entity.manager');
+ $this->menuLinkManager = $this->container->get('plugin.manager.menu.link');
+ $this->menuLinkOverrides = $this->container->get('menu_link.static.overrides');
+ }
+
+ /**
+ * Test views internal menu link options.
+ */
+ public function testMenuLinkOverrides() {
+ // Link from views module.
+ $views_link = $this->menuLinkManager->getDefinition('views_view:views.test_page_display_menu.page_3');
+ $this->assertTrue($views_link['enabled'], 'Menu link is enabled.');
+ $this->assertFalse($views_link['expanded'], 'Menu link is not expanded.');
+ $views_link['enabled'] = 0;
+ $views_link['expanded'] = 1;
+ $this->menuLinkManager->updateDefinition($views_link['id'], $views_link);
+ $views_link = $this->menuLinkManager->getDefinition($views_link['id']);
+ $this->assertFalse($views_link['enabled'], 'Menu link is disabled.');
+ $this->assertTrue($views_link['expanded'], 'Menu link is expanded.');
+ $this->menuLinkManager->rebuild();
+ $this->assertFalse($views_link['enabled'], 'Menu link is disabled.');
+ $this->assertTrue($views_link['expanded'], 'Menu link is expanded.');
+
+ // Link from user module.
+ $user_link = $this->menuLinkManager->getDefinition('user.page');
+ $this->assertTrue($user_link['enabled'], 'Menu link is enabled.');
+ $user_link['enabled'] = 0;
+ $views_link['expanded'] = 1;
+ $this->menuLinkManager->updateDefinition($user_link['id'], $user_link);
+ $this->assertFalse($user_link['enabled'], 'Menu link is disabled.');
+ $this->menuLinkManager->rebuild();
+ $this->assertFalse($user_link['enabled'], 'Menu link is disabled.');
+
+ $this->menuLinkOverrides->reload();
+
+ $views_link = $this->menuLinkManager->getDefinition('views_view:views.test_page_display_menu.page_3');
+ $this->assertFalse($views_link['enabled'], 'Menu link is disabled.');
+ $this->assertTrue($views_link['expanded'], 'Menu link is expanded.');
+
+ $user_link = $this->menuLinkManager->getDefinition('user.page');
+ $this->assertFalse($user_link['enabled'], 'Menu link is disabled.');
+ }
+
+}
diff --git a/core/modules/views/views.install b/core/modules/views/views.install
index 8c5041c..30ac79c 100644
--- a/core/modules/views/views.install
+++ b/core/modules/views/views.install
@@ -368,6 +368,28 @@ function views_update_8100() {
}
/**
+ * Set default values for enabled/expanded flag on page displays.
+ */
+function views_update_8101() {
+ $config_factory = \Drupal::configFactory();
+ foreach ($config_factory->listAll('views.view.') as $view_config_name) {
+ $view = $config_factory->getEditable($view_config_name);
+ $save = FALSE;
+ foreach ($view->get('display') as $display_id => $display) {
+ if ($display['display_plugin'] == 'page') {
+ $display['display_options']['menu']['enabled'] = TRUE;
+ $display['display_options']['menu']['expanded'] = FALSE;
+ $view->set("display.$display_id", $display);
+ $save = TRUE;
+ }
+ }
+ if ($save) {
+ $view->save();
+ }
+ }
+}
+
+/**
* @} End of "addtogroup updates-8.1.0".
*/