diff --git a/core/modules/system/lib/Drupal/system/Annotation/MenuLocalTask.php b/core/modules/system/lib/Drupal/system/Annotation/MenuLocalTask.php index 59e5e42..5fc8e7c 100644 --- a/core/modules/system/lib/Drupal/system/Annotation/MenuLocalTask.php +++ b/core/modules/system/lib/Drupal/system/Annotation/MenuLocalTask.php @@ -24,7 +24,7 @@ class MenuLocalTask extends Plugin { public $id; /** - * The static title for the local action. + * The static title for the local task. * * @ingroup plugin_translatable * diff --git a/core/modules/system/lib/Drupal/system/Plugin/MenuLocalTaskBase.php b/core/modules/system/lib/Drupal/system/Plugin/MenuLocalTaskBase.php index e12c47f..274f09b 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/MenuLocalTaskBase.php +++ b/core/modules/system/lib/Drupal/system/Plugin/MenuLocalTaskBase.php @@ -54,8 +54,7 @@ * The url generator object. */ public function __construct(array $configuration, $plugin_id, array $plugin_definition, TranslatorInterface $string_translation, UrlGeneratorInterface $generator) { - // This is available for subclasses that need to translate - // a dynamic title. + // This is available for subclasses that need to translate a dynamic title. $this->t = $string_translation; $this->generator = $generator; parent::__construct($configuration, $plugin_id, $plugin_definition); @@ -82,7 +81,10 @@ public function getRouteName() { } /** - * {@inheritdoc} + * Returns the localized title to be shown for this tab. + * + * Subclasses may add arguments for request attributes which will then be + * automatically supplied by the controller resolver. */ public function getTitle() { // Subclasses may pull in the request or specific attributes as parameters. @@ -90,15 +92,17 @@ public function getTitle() { } /** - * {@inheritdoc} + * Returns an internal Drupal path to use when creating the link for the tab. + * + * Subclasses may add arguments for request attributes which will then be + * automatically supplied by the controller resolver. */ public function getPath() { - // Subclasses may set a request into the generator or - // use any desired method to generate the path. + // Subclasses may set a request into the generator or use any desired method + // to generate the path. // @todo - use the new method from https://drupal.org/node/2031353 $path = $this->generator->generate($this->getRouteName()); - // In order to get the Drupal path the base URL has - // to be stripped off. + // In order to get the Drupal path the base URL has to be stripped off. $base_url = $this->generator->getContext()->getBaseUrl(); if (!empty($base_url) && strpos($path, $base_url) === 0) { $path = substr($path, strlen($base_url)); @@ -144,6 +148,7 @@ public function getOptions() { */ public function setActive($active = TRUE) { $this->active = $active; + return $this; } /** diff --git a/core/modules/system/lib/Drupal/system/Plugin/MenuLocalTaskInterface.php b/core/modules/system/lib/Drupal/system/Plugin/MenuLocalTaskInterface.php index ce564c5..0db9b1f 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/MenuLocalTaskInterface.php +++ b/core/modules/system/lib/Drupal/system/Plugin/MenuLocalTaskInterface.php @@ -8,7 +8,7 @@ namespace Drupal\system\Plugin; /** - * Defines an interface for menu local actions. + * Defines an interface for menu local tasks. */ interface MenuLocalTaskInterface { @@ -16,30 +16,14 @@ * Get the route name from the settings. * * @return string - * The name of the route this action links to. + * The name of the route this local task links to. */ public function getRouteName(); /** - * Returns the localized title to be shown for this tab. - * - * Subclasses may add optional arguments like NodeInterface $node = NULL that - * will be supplied by the ControllerResolver. - */ - public function getTitle(); - - /** - * Returns an internal Drupal path to use when creating the link for the tab. - * - * Subclasses may add optional arguments like NodeInterface $node = NULL that - * will be supplied by the ControllerResolver. - */ - public function getPath(); - - /** * Returns the weight of the local task. * - * @return int|NULL + * @return int|null * The weight of the task or NULL. */ public function getWeight(); @@ -59,6 +43,9 @@ public function getOptions(); * * @param bool $active * Sets whether this tab is active (e.g. a parent of the current tab). + * + * @return \Drupal\system\Plugin\MenuLocalTaskInterface + * The called object for chaining. */ public function setActive($active = TRUE); @@ -66,7 +53,9 @@ public function setActive($active = TRUE); * Gets the active status. * * @return bool - * TRUE or FALSE. Can be changed by calling setActive(). + * TRUE if the local task is active, FALSE otherwise. + * + * @see \Drupal\system\Plugin\MenuLocalTaskInterface::setActive() */ public function getActive(); diff --git a/core/modules/system/lib/Drupal/system/Plugin/Type/MenuLocalTaskManager.php b/core/modules/system/lib/Drupal/system/Plugin/Type/MenuLocalTaskManager.php index f7a42c1..6f3e247 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Type/MenuLocalTaskManager.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Type/MenuLocalTaskManager.php @@ -18,9 +18,9 @@ /** * Manages discovery and instantiation of menu local task plugins. * - * This manager finds plugs the put a local task (usually a tab) on Drupal - * pages. Derivatives are supported for modules that wish to generate - * new tabs not in code. + * 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 MenuLocalTaskManager extends DefaultPluginManager { @@ -77,33 +77,36 @@ public function __construct(\Traversable $namespaces, ControllerResolverInterfac * Gets the title for a local task. * * @param \Drupal\system\Plugin\MenuLocalTaskInterface $local_task - * An object to get the title from. + * A local task plugin instance to get the title for. * * @return string - * The title (already localized). + * The localized title. */ public function getTitle(MenuLocalTaskInterface $local_task) { - $controller = array($local_task, 'getTitle'); - $arguments = $this->controllerResolver->getArguments($this->request, $controller); - - return call_user_func_array($controller, $arguments); + if (is_callable($controller)) { + $arguments = $this->controllerResolver->getArguments($this->request, $controller); + return call_user_func_array($controller, $arguments); + } + throw new \BadMethodCallException('Menu local task plugins must implement a getTitle() method.'); } /** * Gets the Drupal path for a local task. * * @param \Drupal\system\Plugin\MenuLocalTaskInterface $local_task - * An object to get the path from. + * The local task plugin instance to get the path for. * * @return string * The path. */ public function getPath(MenuLocalTaskInterface $local_task) { $controller = array($local_task, 'getPath'); - $arguments = $this->controllerResolver->getArguments($this->request, $controller); - - return call_user_func_array($controller, $arguments); + if (is_callable($controller)) { + $arguments = $this->controllerResolver->getArguments($this->request, $controller); + return call_user_func_array($controller, $arguments); + } + throw new \BadMethodCallException('Menu local task plugins must implement a getPath() method.'); } /** @@ -115,7 +118,7 @@ public function getPath(MenuLocalTaskInterface $local_task) { * @return array * Returns an array of task levels. Each task level contains instances * of local tasks (MenuLocalTaskInterface) which appear on the tab route. - * The array keys are the depth, and at each depth is an array of + * The array keys are the depths and the values are arrays of plugin * instances. */ public function getLocalTasksForRoute($route_name) { @@ -184,7 +187,7 @@ public function getLocalTasksForRoute($route_name) { } /** - * Get the render array for all local tasks. + * Gets the render array for all local tasks. * * @param string $route_name * The route for which to make renderable local tasks.