summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2014-09-29 00:11:38 (GMT)
committerwebchick2014-09-29 00:11:38 (GMT)
commitf140282e2665dd086b380c92e76a51507bcb4a3c (patch)
tree5dfca3e6da17f664080bbb2b2cad323aabc171bd
parentccede8293e6267c9382b838b7d91d4592d040021 (diff)
Issue #2323511 by dawehner, pfrenssen, olli, Xano | alberto56: Fixed Menu dropdown missing from 'Normal menu entry' section in Views.
-rw-r--r--core/modules/node/config/install/views.view.glossary.yml2
-rw-r--r--core/modules/views/config/schema/views.display.schema.yml3
-rw-r--r--core/modules/views/src/Entity/View.php17
-rw-r--r--core/modules/views/src/Plugin/Menu/ViewsMenuLink.php13
-rw-r--r--core/modules/views/src/Plugin/views/PluginBase.php9
-rw-r--r--core/modules/views/src/Plugin/views/display/Block.php52
-rw-r--r--core/modules/views/src/Plugin/views/display/DisplayPluginBase.php13
-rw-r--r--core/modules/views/src/Plugin/views/display/Page.php8
-rw-r--r--core/modules/views/src/Tests/ViewTestBase.php6
-rw-r--r--core/modules/views/tests/modules/views_test_config/test_views/views.view.test_page_display_menu.yml18
-rw-r--r--core/modules/views_ui/src/Tests/DisplayPathTest.php29
11 files changed, 154 insertions, 16 deletions
diff --git a/core/modules/node/config/install/views.view.glossary.yml b/core/modules/node/config/install/views.view.glossary.yml
index 64541c6..f7ccaef 100644
--- a/core/modules/node/config/install/views.view.glossary.yml
+++ b/core/modules/node/config/install/views.view.glossary.yml
@@ -369,6 +369,8 @@ display:
type: normal
title: Glossary
weight: 0
+ menu_name: main
+ parent: ''
field_langcode: '***LANGUAGE_language_content***'
field_langcode_add_to_query: null
attachment_1:
diff --git a/core/modules/views/config/schema/views.display.schema.yml b/core/modules/views/config/schema/views.display.schema.yml
index 212941b..6531990 100644
--- a/core/modules/views/config/schema/views.display.schema.yml
+++ b/core/modules/views/config/schema/views.display.schema.yml
@@ -37,6 +37,9 @@ views.display.page:
menu_name:
type: string
label: 'Menu name'
+ parent:
+ type: string
+ label: 'Parent'
context:
type: string
label: 'Context'
diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php
index 1ad685a..ea3664e 100644
--- a/core/modules/views/src/Entity/View.php
+++ b/core/modules/views/src/Entity/View.php
@@ -348,6 +348,23 @@ class View extends ConfigEntityBase implements ViewStorageInterface {
/**
* {@inheritdoc}
*/
+ public static function preDelete(EntityStorageInterface $storage, array $entities) {
+ parent::preDelete($storage, $entities);
+
+ // Call the remove() hook on the individual displays.
+ /** @var \Drupal\views\ViewStorageInterface $entity */
+ foreach ($entities as $entity) {
+ $executable = Views::executableFactory()->get($entity);
+ foreach ($entity->get('display') as $display_id => $display) {
+ $executable->setDisplay($display_id);
+ $executable->getDisplay()->remove();
+ }
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities);
diff --git a/core/modules/views/src/Plugin/Menu/ViewsMenuLink.php b/core/modules/views/src/Plugin/Menu/ViewsMenuLink.php
index a07862f..85c2350 100644
--- a/core/modules/views/src/Plugin/Menu/ViewsMenuLink.php
+++ b/core/modules/views/src/Plugin/Menu/ViewsMenuLink.php
@@ -154,4 +154,17 @@ class ViewsMenuLink extends MenuLinkBase implements ContainerFactoryPluginInterf
return $this->pluginDefinition;
}
+ /**
+ * {@inheritdoc}
+ */
+ public function isDeletable() {
+ return TRUE;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function deleteLink() {
+ }
+
}
diff --git a/core/modules/views/src/Plugin/views/PluginBase.php b/core/modules/views/src/Plugin/views/PluginBase.php
index 1b66bdc..17f39e1 100644
--- a/core/modules/views/src/Plugin/views/PluginBase.php
+++ b/core/modules/views/src/Plugin/views/PluginBase.php
@@ -92,7 +92,14 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
/**
- * Constructs a Plugin object.
+ * Constructs a PluginBase object.
+ *
+ * @param array $configuration
+ * A configuration array containing information about the plugin instance.
+ * @param string $plugin_id
+ * The plugin_id for the plugin instance.
+ * @param mixed $plugin_definition
+ * The plugin implementation definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
diff --git a/core/modules/views/src/Plugin/views/display/Block.php b/core/modules/views/src/Plugin/views/display/Block.php
index ffb40b6..5986381 100644
--- a/core/modules/views/src/Plugin/views/display/Block.php
+++ b/core/modules/views/src/Plugin/views/display/Block.php
@@ -8,8 +8,10 @@
namespace Drupal\views\Plugin\views\display;
use Drupal\Component\Utility\String;
+use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\Block\ViewsBlock;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* The plugin that handles a block.
@@ -39,6 +41,46 @@ class Block extends DisplayPluginBase {
*/
protected $usesAttachments = TRUE;
+ /**
+ * The entity manager.
+ *
+ * @var \Drupal\Core\Entity\EntityManagerInterface
+ */
+ protected $entityManager;
+
+ /**
+ * Constructs a new Block instance.
+ *
+ * @param array $configuration
+ * A configuration array containing information about the plugin instance.
+ * @param string $plugin_id
+ * The plugin_id for the plugin instance.
+ * @param mixed $plugin_definition
+ * The plugin implementation definition.
+ * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
+ * The entity manager.
+ */
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) {
+ parent::__construct($configuration, $plugin_id, $plugin_definition);
+
+ $this->entityManager = $entity_manager;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+ return new static(
+ $configuration,
+ $plugin_id,
+ $plugin_definition,
+ $container->get('entity.manager')
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
protected function defineOptions() {
$options = parent::defineOptions();
@@ -316,14 +358,16 @@ class Block extends DisplayPluginBase {
}
/**
- * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::remove().
+ * {@inheritdoc}
*/
public function remove() {
parent::remove();
- $plugin_id = 'views_block:' . $this->view->storage->id() . '-' . $this->display['id'];
- foreach (entity_load_multiple_by_properties('block', array('plugin' => $plugin_id)) as $block) {
- $block->delete();
+ if ($this->entityManager->hasDefinition('block')) {
+ $plugin_id = 'views_block:' . $this->view->storage->id() . '-' . $this->display['id'];
+ foreach ($this->entityManager->getStorage('block')->loadByProperties(['plugin' => $plugin_id]) as $block) {
+ $block->delete();
+ }
}
}
diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
index 5348df1..0dd89bb 100644
--- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
+++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
@@ -134,6 +134,13 @@ abstract class DisplayPluginBase extends PluginBase {
*
* @todo Replace DisplayPluginBase::$display with
* DisplayPluginBase::$configuration to standardize with other plugins.
+ *
+ * @param array $configuration
+ * A configuration array containing information about the plugin instance.
+ * @param string $plugin_id
+ * The plugin_id for the plugin instance.
+ * @param mixed $plugin_definition
+ * The plugin implementation definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct(array(), $plugin_id, $plugin_definition);
@@ -2389,6 +2396,12 @@ abstract class DisplayPluginBase extends PluginBase {
* Reacts on deleting a display.
*/
public function remove() {
+ $menu_links = $this->getMenuLinks();
+ /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
+ $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
+ foreach ($menu_links as $menu_link_id => $menu_link) {
+ $menu_link_manager->removeDefinition("views_view:$menu_link_id");
+ }
}
/**
diff --git a/core/modules/views/src/Plugin/views/display/Page.php b/core/modules/views/src/Plugin/views/display/Page.php
index 08da0a2..5234f2c 100644
--- a/core/modules/views/src/Plugin/views/display/Page.php
+++ b/core/modules/views/src/Plugin/views/display/Page.php
@@ -50,7 +50,7 @@ class Page extends PathPluginBase {
'title' => array('default' => '', 'translatable' => FALSE),
'description' => array('default' => '', 'translatable' => FALSE),
'weight' => array('default' => 0),
- 'menu_name' => array('default' => 'navigation'),
+ 'menu_name' => array('default' => 'main'),
'parent' => array('default' => ''),
'context' => array('default' => ''),
),
@@ -62,7 +62,7 @@ class Page extends PathPluginBase {
'title' => array('default' => '', 'translatable' => FALSE),
'description' => array('default' => '', 'translatable' => FALSE),
'weight' => array('default' => 0),
- 'menu_name' => array('default' => 'navigation'),
+ 'menu_name' => array('default' => 'main'),
),
);
@@ -338,11 +338,11 @@ class Page extends PathPluginBase {
);
// Only display the menu selector if Menu UI module is enabled.
if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
- $form['tab_options']['name'] = array(
+ $form['tab_options']['menu_name'] = array(
'#title' => $this->t('Menu'),
'#type' => 'select',
'#options' => menu_ui_get_menus(),
- '#default_value' => $tab_options['name'],
+ '#default_value' => $tab_options['menu_name'],
'#description' => $this->t('Insert item into an available menu.'),
'#states' => array(
'visible' => array(
diff --git a/core/modules/views/src/Tests/ViewTestBase.php b/core/modules/views/src/Tests/ViewTestBase.php
index 82e42e2..6aa899d 100644
--- a/core/modules/views/src/Tests/ViewTestBase.php
+++ b/core/modules/views/src/Tests/ViewTestBase.php
@@ -33,12 +33,6 @@ abstract class ViewTestBase extends WebTestBase {
protected function setUp() {
parent::setUp();
- // Views' Page displays put menu links in the 'navigation' menu by default.
- entity_create('menu', array(
- 'id' => 'navigation',
- 'label' => 'Navigation',
- ))->save();
-
// Ensure that the plugin definitions are cleared.
foreach (ViewExecutable::getPluginTypes() as $plugin_type) {
$this->container->get("plugin.manager.views.$plugin_type")->clearCachedDefinitions();
diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_page_display_menu.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_page_display_menu.yml
index cd812f2..7b6efae 100644
--- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_page_display_menu.yml
+++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_page_display_menu.yml
@@ -97,6 +97,24 @@ display:
display_title: Page
id: page_4
position: 0
+ page_5:
+ display_options:
+ path: test-path
+ title: 'Tests a menu with a non-existing parent'
+ menu:
+ type: normal
+ title: 'Test child'
+ parent: 'system.admin'
+ description: ''
+ name: not-existing-menu-name
+ 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: ''
diff --git a/core/modules/views_ui/src/Tests/DisplayPathTest.php b/core/modules/views_ui/src/Tests/DisplayPathTest.php
index 38f662e..7e553e3 100644
--- a/core/modules/views_ui/src/Tests/DisplayPathTest.php
+++ b/core/modules/views_ui/src/Tests/DisplayPathTest.php
@@ -16,12 +16,20 @@ namespace Drupal\views_ui\Tests;
class DisplayPathTest extends UITestBase {
/**
+ * {@inheritdoc}
+ */
+ public static $modules = array('menu_ui');
+
+ /**
* Views used by this test.
*
* @var array
*/
- public static $testViews = array('test_view');
+ public static $testViews = array('test_view', 'test_page_display_menu');
+ /**
+ * Runs the tests.
+ */
public function testPathUI() {
$this->doBasicPathUITest();
$this->doAdvancedPathsValidationTest();
@@ -96,6 +104,25 @@ class DisplayPathTest extends UITestBase {
$this->assertLink(t('Tab: @title', array('@title' => 'Test tab title')));
// If it's a default tab, it should also have an additional settings link.
$this->assertLinkByHref('admin/structure/views/nojs/display/test_view/page_1/tab_options');
+
+ // Ensure that you can select a parent in case the parent does not exist.
+ $this->drupalGet('admin/structure/views/nojs/display/test_page_display_menu/page_5/menu');
+ $this->assertResponse(200);
+ $menu_parent = $this->xpath('//select[@id="edit-menu-parent"]');
+ $menu_options = (array) $menu_parent[0]->option;
+ unset($menu_options['@attributes']);
+
+ $this->assertEqual([
+ '<User account menu>',
+ '-- My account',
+ '-- Log out',
+ '<Administration>',
+ '<Footer>',
+ '<Main navigation>',
+ '<Tools>',
+ '-- Compose tips (disabled)',
+ '-- Test menu link',
+ ], $menu_options);
}
}