Commit fa529482 authored by alexpott's avatar alexpott

Issue #2464077 by webflo, s_leu, dawehner, Lendude: Menu link overrides are...

Issue #2464077 by webflo, s_leu, dawehner, Lendude: Menu link overrides are lost after cache rebuild
parent 8ed14e0e
...@@ -34,6 +34,12 @@ views.display.page: ...@@ -34,6 +34,12 @@ views.display.page:
weight: weight:
type: integer type: integer
label: 'Weight' label: 'Weight'
enabled:
type: boolean
label: 'Enabled'
expanded:
type: boolean
label: 'Expanded'
menu_name: menu_name:
type: string type: string
label: 'Menu name' label: 'Menu name'
......
...@@ -26,7 +26,6 @@ class ViewsMenuLink extends MenuLinkBase implements ContainerFactoryPluginInterf ...@@ -26,7 +26,6 @@ class ViewsMenuLink extends MenuLinkBase implements ContainerFactoryPluginInterf
'enabled' => 1, 'enabled' => 1,
'title' => 1, 'title' => 1,
'description' => 1, 'description' => 1,
'metadata' => 1,
); );
/** /**
...@@ -140,9 +139,9 @@ public function updateLink(array $new_definition_values, $persist) { ...@@ -140,9 +139,9 @@ public function updateLink(array $new_definition_values, $persist) {
$display = &$view->storage->getDisplay($view->current_display); $display = &$view->storage->getDisplay($view->current_display);
// Just save the title to the original view. // Just save the title to the original view.
$changed = FALSE; $changed = FALSE;
foreach ($new_definition_values as $key => $new_definition_value) { foreach ($overrides as $key => $new_definition_value) {
if (isset($display['display_options']['menu'][$key]) && $display['display_options']['menu'][$key] != $new_definition_values[$key]) { if (empty($display['display_options']['menu'][$key]) || $display['display_options']['menu'][$key] != $new_definition_value) {
$display['display_options']['menu'][$key] = $new_definition_values[$key]; $display['display_options']['menu'][$key] = $new_definition_value;
$changed = TRUE; $changed = TRUE;
} }
} }
......
...@@ -124,6 +124,7 @@ protected function defineOptions() { ...@@ -124,6 +124,7 @@ protected function defineOptions() {
'title' => array('default' => ''), 'title' => array('default' => ''),
'description' => array('default' => ''), 'description' => array('default' => ''),
'weight' => array('default' => 0), 'weight' => array('default' => 0),
'enabled' => array('default' => TRUE),
'menu_name' => array('default' => 'main'), 'menu_name' => array('default' => 'main'),
'parent' => array('default' => ''), 'parent' => array('default' => ''),
'context' => array('default' => ''), 'context' => array('default' => ''),
......
...@@ -322,6 +322,8 @@ public function getMenuLinks() { ...@@ -322,6 +322,8 @@ public function getMenuLinks() {
$links[$menu_link_id]['title'] = $menu['title']; $links[$menu_link_id]['title'] = $menu['title'];
$links[$menu_link_id]['description'] = $menu['description']; $links[$menu_link_id]['description'] = $menu['description'];
$links[$menu_link_id]['parent'] = $menu['parent']; $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'])) { if (isset($menu['weight'])) {
$links[$menu_link_id]['weight'] = intval($menu['weight']); $links[$menu_link_id]['weight'] = intval($menu['weight']);
......
<?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.');
}
}
...@@ -367,6 +367,28 @@ function views_update_8100() { ...@@ -367,6 +367,28 @@ function views_update_8100() {
// Empty update to cause a cache flush so that views data is rebuilt. // Empty update to cause a cache flush so that views data is rebuilt.
} }
/**
* 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". * @} End of "addtogroup updates-8.1.0".
*/ */
......
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