Skip to content
Snippets Groups Projects
Commit cd240fd2 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2312077 by dawehner: Provide interfaces for the local task and action manager.

parent a4b6e3b1
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -21,14 +21,9 @@ ...@@ -21,14 +21,9 @@
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
/** /**
* Manages discovery and instantiation of menu local action plugins. * Provides the default local action manager using YML as primary definition.
*
* Menu local actions are links that lead to actions like "add new". The plugin
* format allows them (if needed) to dynamically generate a title or the path
* they link to. The annotation on the plugin provides the default title,
* and the list of routes where the action should be rendered.
*/ */
class LocalActionManager extends DefaultPluginManager { class LocalActionManager extends DefaultPluginManager implements LocalActionManagerInterface {
/** /**
* Provides some default values for all local action plugins. * Provides some default values for all local action plugins.
...@@ -133,16 +128,7 @@ public function __construct(ControllerResolverInterface $controller_resolver, Re ...@@ -133,16 +128,7 @@ public function __construct(ControllerResolverInterface $controller_resolver, Re
} }
/** /**
* Gets the title for a local action. * {@inheritdoc}
*
* @param \Drupal\Core\Menu\LocalActionInterface $local_action
* An object to get the title from.
*
* @return string
* The title (already localized).
*
* @throws \BadMethodCallException
* If the plugin does not implement the getTitle() method.
*/ */
public function getTitle(LocalActionInterface $local_action) { public function getTitle(LocalActionInterface $local_action) {
$controller = array($local_action, 'getTitle'); $controller = array($local_action, 'getTitle');
...@@ -151,13 +137,7 @@ public function getTitle(LocalActionInterface $local_action) { ...@@ -151,13 +137,7 @@ public function getTitle(LocalActionInterface $local_action) {
} }
/** /**
* Finds all local actions that appear on a named route. * {@inheritdoc}
*
* @param string $route_appears
* The route name for which to find local actions.
*
* @return array
* An array of link render arrays.
*/ */
public function getActionsForRoute($route_appears) { public function getActionsForRoute($route_appears) {
if (!isset($this->instances[$route_appears])) { if (!isset($this->instances[$route_appears])) {
......
<?php
/**
* @file
* Contains \Drupal\Core\Menu\LocalActionManagerInterface.
*/
namespace Drupal\Core\Menu;
use Drupal\Component\Plugin\PluginManagerInterface;
/**
* Manages discovery and instantiation of menu local action plugins.
*
* Menu local actions are links that lead to actions like "add new". The plugin
* format allows them (if needed) to dynamically generate a title or the path
* they link to. The annotation on the plugin provides the default title,
* and the list of routes where the action should be rendered.
*/
interface LocalActionManagerInterface extends PluginManagerInterface {
/**
* Gets the title for a local action.
*
* @param \Drupal\Core\Menu\LocalActionInterface $local_action
* An object to get the title from.
*
* @return string
* The title (already localized).
*
* @throws \BadMethodCallException
* If the plugin does not implement the getTitle() method.
*/
public function getTitle(LocalActionInterface $local_action);
/**
* Finds all local actions that appear on a named route.
*
* @param string $route_appears
* The route name for which to find local actions.
*
* @return array
* An array of link render arrays.
*/
public function getActionsForRoute($route_appears);
}
...@@ -24,13 +24,9 @@ ...@@ -24,13 +24,9 @@
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
/** /**
* Manages discovery and instantiation of menu local task plugins. * Provides the default local task manager using YML as primary definition.
*
* This manager finds plugins that are rendered as local tasks (usually tabs).
* Derivatives are supported for modules that wish to generate multiple tabs on
* behalf of something else.
*/ */
class LocalTaskManager extends DefaultPluginManager { class LocalTaskManager extends DefaultPluginManager implements LocalTaskManagerInterface {
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -154,13 +150,7 @@ public function processDefinition(&$definition, $plugin_id) { ...@@ -154,13 +150,7 @@ public function processDefinition(&$definition, $plugin_id) {
} }
/** /**
* Gets the title for a local task. * {@inheritdoc}
*
* @param \Drupal\Core\Menu\LocalTaskInterface $local_task
* A local task plugin instance to get the title for.
*
* @return string
* The localized title.
*/ */
public function getTitle(LocalTaskInterface $local_task) { public function getTitle(LocalTaskInterface $local_task) {
$controller = array($local_task, 'getTitle'); $controller = array($local_task, 'getTitle');
...@@ -187,16 +177,7 @@ public function getDefinitions() { ...@@ -187,16 +177,7 @@ public function getDefinitions() {
} }
/** /**
* Find all local tasks that appear on a named route. * {@inheritdoc}
*
* @param string $route_name
* The route for which to find local tasks.
*
* @return array
* Returns an array of task levels. Each task level contains instances
* of local tasks (LocalTaskInterface) which appear on the tab route.
* The array keys are the depths and the values are arrays of plugin
* instances.
*/ */
public function getLocalTasksForRoute($route_name) { public function getLocalTasksForRoute($route_name) {
if (!isset($this->instances[$route_name])) { if (!isset($this->instances[$route_name])) {
...@@ -290,13 +271,7 @@ public function getLocalTasksForRoute($route_name) { ...@@ -290,13 +271,7 @@ public function getLocalTasksForRoute($route_name) {
} }
/** /**
* Gets the render array for all local tasks. * {@inheritdoc}
*
* @param string $current_route_name
* The route for which to make renderable local tasks.
*
* @return array
* A render array as expected by theme_menu_local_tasks.
*/ */
public function getTasksBuild($current_route_name) { public function getTasksBuild($current_route_name) {
$tree = $this->getLocalTasksForRoute($current_route_name); $tree = $this->getLocalTasksForRoute($current_route_name);
......
<?php
/**
* @file
* Contains \Drupal\Core\Menu\LocalTaskManagerInterface.
*/
namespace Drupal\Core\Menu;
use Drupal\Component\Plugin\PluginManagerInterface;
/**
* Manages discovery and instantiation of menu local task plugins.
*
* This manager finds plugins that are rendered as local tasks (usually tabs).
* Derivatives are supported for modules that wish to generate multiple tabs on
* behalf of something else.
*/
interface LocalTaskManagerInterface extends PluginManagerInterface {
/**
* Gets the title for a local task.
*
* @param \Drupal\Core\Menu\LocalTaskInterface $local_task
* A local task plugin instance to get the title for.
*
* @return string
* The localized title.
*/
public function getTitle(LocalTaskInterface $local_task);
/**
* Find all local tasks that appear on a named route.
*
* @param string $route_name
* The route for which to find local tasks.
*
* @return array
* Returns an array of task levels. Each task level contains instances
* of local tasks (LocalTaskInterface) which appear on the tab route.
* The array keys are the depths and the values are arrays of plugin
* instances.
*/
public function getLocalTasksForRoute($route_name);
/**
* Gets the render array for all local tasks.
*
* @param string $current_route_name
* The route for which to make renderable local tasks.
*
* @return array
* A render array as expected by theme_menu_local_tasks.
*/
public function getTasksBuild($current_route_name);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment