Commit f140282e authored by webchick's avatar webchick

Issue #2323511 by dawehner, pfrenssen, olli, Xano | alberto56: Fixed Menu...

Issue #2323511 by dawehner, pfrenssen, olli, Xano | alberto56: Fixed Menu dropdown missing from 'Normal menu entry' section in Views.
parent ccede829
......@@ -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:
......
......@@ -37,6 +37,9 @@ views.display.page:
menu_name:
type: string
label: 'Menu name'
parent:
type: string
label: 'Parent'
context:
type: string
label: 'Context'
......
......@@ -345,6 +345,23 @@ public function postCreate(EntityStorageInterface $storage) {
$this->mergeDefaultDisplaysOptions();
}
/**
* {@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}
*/
......
......@@ -154,4 +154,17 @@ public function updateLink(array $new_definition_values, $persist) {
return $this->pluginDefinition;
}
/**
* {@inheritdoc}
*/
public function isDeletable() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function deleteLink() {
}
}
......@@ -92,7 +92,14 @@
/**
* 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);
......
......@@ -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 @@ public function usesExposed() {
}
/**
* 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();
}
}
}
......
......@@ -134,6 +134,13 @@
*
* @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 @@ public function newDisplay() {
* 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");
}
}
/**
......
......@@ -50,7 +50,7 @@ protected function defineOptions() {
'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 @@ protected function defineOptions() {
'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 @@ 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['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(
......
......@@ -33,12 +33,6 @@
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();
......
......@@ -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: ''
......@@ -15,13 +15,21 @@
*/
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 @@ public function testMenuOptions() {
$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);
}
}
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