Commit cd240fd2 authored by webchick's avatar webchick

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

parent a4b6e3b1
......@@ -21,14 +21,9 @@
use Drupal\Core\Session\AccountInterface;
/**
* 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.
* Provides the default local action manager using YML as primary definition.
*/
class LocalActionManager extends DefaultPluginManager {
class LocalActionManager extends DefaultPluginManager implements LocalActionManagerInterface {
/**
* Provides some default values for all local action plugins.
......@@ -133,16 +128,7 @@ public function __construct(ControllerResolverInterface $controller_resolver, Re
}
/**
* 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.
* {@inheritdoc}
*/
public function getTitle(LocalActionInterface $local_action) {
$controller = array($local_action, 'getTitle');
......@@ -151,13 +137,7 @@ 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.
* {@inheritdoc}
*/
public function getActionsForRoute($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 @@
use Symfony\Component\HttpFoundation\RequestStack;
/**
* 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.
* Provides the default local task manager using YML as primary definition.
*/
class LocalTaskManager extends DefaultPluginManager {
class LocalTaskManager extends DefaultPluginManager implements LocalTaskManagerInterface {
/**
* {@inheritdoc}
......@@ -154,13 +150,7 @@ public function processDefinition(&$definition, $plugin_id) {
}
/**
* 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.
* {@inheritdoc}
*/
public function getTitle(LocalTaskInterface $local_task) {
$controller = array($local_task, 'getTitle');
......@@ -187,16 +177,7 @@ public function getDefinitions() {
}
/**
* 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.
* {@inheritdoc}
*/
public function getLocalTasksForRoute($route_name) {
if (!isset($this->instances[$route_name])) {
......@@ -290,13 +271,7 @@ 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.
* {@inheritdoc}
*/
public function getTasksBuild($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);
}
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