Commit 3c12e215 authored by alexpott's avatar alexpott

Issue #2498785 by damiankloip, dawehner: Remove ViewExecutable::getMenuLinks(), its just wrong

parent 999332b6
......@@ -9,6 +9,7 @@
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\views\Plugin\views\display\DisplayMenuInterface;
use Drupal\views\Views;
use Drupal\Core\Entity\EntityStorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -57,8 +58,10 @@ public function getDerivativeDefinitions($base_plugin_definition) {
list($view_id, $display_id) = $data;
/** @var \Drupal\views\ViewExecutable $executable */
$executable = $this->viewStorage->load($view_id)->getExecutable();
$executable->initDisplay();
$display = $executable->displayHandlers->get($display_id);
if ($result = $executable->getMenuLinks($display_id)) {
if (($display instanceof DisplayMenuInterface) && ($result = $display->getMenuLinks())) {
foreach ($result as $link_id => $link) {
$links[$link_id] = $link + $base_plugin_definition;
}
......
<?php
/**
* @file
* Contains \Drupal\views\Plugin\views\display\DisplayMenuInterface.
*/
namespace Drupal\views\Plugin\views\display;
/**
* Defines an interface for displays that provide menu links.
*/
interface DisplayMenuInterface {
/**
* Gets menu links, if this display provides some.
*
* @return array
* The menu links registers for this display.
*
* @see \Drupal\views\Plugin\Derivative\ViewsMenuLink
*/
public function getMenuLinks();
}
......@@ -2112,13 +2112,6 @@ public function renderMoreLink() {
}
}
/**
* {@inheritdoc}
*/
public function getMenuLinks() {
return array();
}
/**
* {@inheritdoc}
*/
......@@ -2472,18 +2465,6 @@ public function validate() {
public function newDisplay() {
}
/**
* {@inheritdoc}
*/
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");
}
}
/**
* {@inheritdoc}
*/
......@@ -2611,6 +2592,13 @@ public function mergeDefaults() {
}
}
/**
* {@inheritdoc}
*/
public function remove() {
}
/**
* Merges plugins default values.
*
......
......@@ -381,16 +381,6 @@ public function renderPager();
*/
public function renderMoreLink();
/**
* Gets menu links, if this display provides some.
*
* @return array
* The menu links registers for this display.
*
* @see \Drupal\views\Plugin\Derivative\ViewsMenuLink
*/
public function getMenuLinks();
/**
* Renders this display.
*/
......
......@@ -71,4 +71,5 @@ public function getRouteName();
* @see \Drupal\views\Plugin\views\display\DisplayRouterInterface::alterRoutes()
*/
public function getAlteredRouteNames();
}
......@@ -29,7 +29,7 @@
*
* @see \Drupal\views\EventSubscriber\RouteSubscriber
*/
abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouterInterface {
abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouterInterface, DisplayMenuInterface {
use UrlGeneratorTrait;
......@@ -521,4 +521,16 @@ public function getAlteredRouteNames() {
return $this->state->get('views.view_route_names') ?: array();
}
/**
* {@inheritdoc}
*/
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");
}
}
}
......@@ -1615,29 +1615,6 @@ public function attachDisplays() {
$this->is_attachment = FALSE;
}
/**
* Returns menu links from the view and the named display handler.
*
* @param string $display_id
* A display ID.
*
* @return array|bool
* The generated menu links for this view and display, FALSE if the call
* to ::setDisplay failed.
*/
public function getMenuLinks($display_id = NULL) {
// Prepare the view with the information we have. This was probably already
// called, but it's good to be safe.
if (!$this->setDisplay($display_id)) {
return FALSE;
}
// Execute the hook.
if (isset($this->display_handler)) {
return $this->display_handler->getMenuLinks();
}
}
/**
* Determine if the given user has access to the view. Note that
* this sets the display handler if it hasn't been.
......
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