diff --git a/core/lib/Drupal/Core/Menu/ContextualLinkInterface.php b/core/lib/Drupal/Core/Menu/ContextualLinkInterface.php index b1e566b..7ee9aef 100644 --- a/core/lib/Drupal/Core/Menu/ContextualLinkInterface.php +++ b/core/lib/Drupal/Core/Menu/ContextualLinkInterface.php @@ -34,7 +34,14 @@ public function getTitle(); public function getRouteName(); /** - * Returns the group this contextual link should be rendered on. + * Returns the group this contextual link should be rendered in. + * + * A contextual link group is a bunch of contextual link displayed together on + * the page. For example the block group displays all links related with the + * block, like the block instance edit link as well as the views edit link, + * if it is a view block. + * + * The name of a group has to be unique. * * @return string * The contextual links group name. diff --git a/core/lib/Drupal/Core/Menu/ContextualLinkManager.php b/core/lib/Drupal/Core/Menu/ContextualLinkManager.php index 9851488..1ce55af 100644 --- a/core/lib/Drupal/Core/Menu/ContextualLinkManager.php +++ b/core/lib/Drupal/Core/Menu/ContextualLinkManager.php @@ -94,11 +94,11 @@ public function processDefinition(&$definition, $plugin_id) { // If there is no route name, this is a broken definition. if (empty($definition['route_name'])) { - throw new PluginException(sprintf('Plugin (%s) definition must include "route_name".', $plugin_id)); + throw new PluginException(sprintf('Contextual link plugin (%s) definition must include "route_name".', $plugin_id)); } // If there is no group name, this is a broken definition. if (empty($definition['group'])) { - throw new PluginException(sprintf('Plugin (%s) definition must include "group".', $plugin_id)); + throw new PluginException(sprintf('Contextual link plugin (%s) definition must include "group".', $plugin_id)); } } @@ -133,7 +133,9 @@ public function getContextualLinkPluginsByGroup($group_name) { * @param string $group_name * The group name. * @param array $route_parameters - * The incoming route parameters. + * The incoming route parameters. This route parameters need to have the + * same name on all contextual link routes, e.g. you cannot use node and + * entity in parallel. * * @return array * A list of links as array, keyed by the plugin ID. Each entry is an diff --git a/core/modules/contextual/contextual.module b/core/modules/contextual/contextual.module index cee06c3..14e7249 100644 --- a/core/modules/contextual/contextual.module +++ b/core/modules/contextual/contextual.module @@ -335,8 +335,8 @@ function _contextual_links_to_id($contextual_links) { foreach ($contextual_links as $module => $args) { $group = $args[0]; $route_parameters = drupal_http_build_query($args[1]); - $options = drupal_http_build_query((isset($args[2])) ? $args[2] : array()); - $ids[] = "{$module}:{$group}:{$route_parameters}:{$options}"; + $metadata = drupal_http_build_query((isset($args[2])) ? $args[2] : array()); + $ids[] = "{$module}:{$group}:{$route_parameters}:{$metadata}"; } return implode('|', $ids); } @@ -356,12 +356,11 @@ function _contextual_id_to_links($id) { $contextual_links = array(); $contexts = explode('|', $id); foreach ($contexts as $context) { - list($module, $parent_path, $args_raw, $metadata_raw) = explode(':', $context); - $path_args = array(); - parse_str($args_raw, $path_args); + list($module, $group, $route_parameters_raw, $metadata_raw) = explode(':', $context); + parse_str($route_parameters_raw, $route_parameters); $metadata = array(); parse_str($metadata_raw, $metadata); - $contextual_links[$module] = array($parent_path, $path_args, $metadata); + $contextual_links[$module] = array($group, $route_parameters, $metadata); } return $contextual_links; } diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index ca499cc..c1aed43 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -984,9 +984,9 @@ function hook_menu_contextual_links_alter(&$links, $router_item, $root_path) { * This hook is invoked by * \Drupal\Core\Menu\ContextualLinkManager::getContextualLinkPluginsByGroup(). * The system-determined contextual links are passed in by reference. Additional - * links may be added or existing links can be altered. + * links may be added and existing links can be altered. * - * Each contextual link must at least contain: + * Each contextual link must contain at least: * - title: The localized title of the link. * - route_name: The route name of the link. * - route_parameters: The route parameters of the link. @@ -998,10 +998,10 @@ function hook_menu_contextual_links_alter(&$links, $router_item, $root_path) { * contextual links and must therefore be unique for each set of contextual * links. * @param string $group - * The contextual links group name being requested. + * The group of contextual links being rendered. * @param array $route_parameters. * The route parameters passed to each route_name of the contextual links. - * So for example it is an array like that: + * So e.g. it is an array like that: * @code * node => $node->id(). * @endcode @@ -1010,10 +1010,10 @@ function hook_menu_contextual_links_alter(&$links, $router_item, $root_path) { */ function hook_contextual_links_alter(array &$links, $group, array $route_parameters) { if ($group == 'menu') { - // Dynamically use the menu name for the title of the menu edit contextual + // Dynamically use the menu name for the title of the menu_edit contextual // link. $menu = \Drupal::entityManager()->getStorageController('menu')->load($route_parameters['menu']); - $links['menu_edit']['title'] = 'Edit menu: ' . $menu->label(); + $links['menu_edit']['title'] = t('Edit menu: @label', array('@label' => $menu->label())); } } @@ -1021,12 +1021,12 @@ function hook_contextual_links_alter(array &$links, $group, array $route_paramet * Alters the plugin definition of contextual links. * * @param array $contextual_links - * An array of contextual_links plugin definitions, keyed by plugin ID. - * Each entry contains the following keys: + * An array of contextual_links plugin definitions, keyed by contextual link + * ID. Each entry contains the following keys: * - title: The displayed title of the link * - route_name: The route_name of the contextual link to be displayed * - group: The group under which the contextual links should be added to. - * Possible values are for example 'node' or 'menu'. + * Possible values are e.g. 'node' or 'menu'. * * @see \Drupal\Core\Menu\ContextualLinkManager */ diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php index 15db4d5..4d7113e 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php @@ -164,7 +164,7 @@ public function testGetContextualLinkPluginsByGroup() { } /** - * Tests the getContextualLinkPluginsByGroup with a prefilled cache. + * Tests the getContextualLinkPluginsByGroup method with a prefilled cache. */ public function testGetContextualLinkPluginsByGroupWithCache() { $definitions = array( @@ -267,7 +267,7 @@ public function testGetContextualLinksArrayByGroup() { ->method('checkNamedRoute') ->will($this->returnValue(TRUE)); - // Setup mocking of the plugin factory. + // Set up mocking of the plugin factory. $map = array(); foreach ($definitions as $plugin_id => $definition) { $plugin = $this->getMock('Drupal\Core\Menu\ContextualLinkInterface'); @@ -336,7 +336,7 @@ public function testGetContextualLinksArrayByGroupAccessCheck() { array('test_route2', array('key' => 'value'), NULL, FALSE), ))); - // Setup mocking of the plugin factory. + // Set up mocking of the plugin factory. $map = array(); foreach ($definitions as $plugin_id => $definition) { $plugin = $this->getMock('Drupal\Core\Menu\ContextualLinkInterface'); diff --git a/core/vendor/phpunit/phpunit/PHPUnit/Framework/Comparator/Array.php b/core/vendor/phpunit/phpunit/PHPUnit/Framework/Comparator/Array.php index d715514..ebbf928 100644 --- a/core/vendor/phpunit/phpunit/PHPUnit/Framework/Comparator/Array.php +++ b/core/vendor/phpunit/phpunit/PHPUnit/Framework/Comparator/Array.php @@ -165,7 +165,7 @@ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FAL $expString, $actString, FALSE, - 'Failed asserting that two arrays are equal. ' . print_r(array_diff_assoc($expected, $actual), TRUE) + 'Failed asserting that two arrays are equal.' ); } }