diff -u b/core/includes/theme.inc b/core/includes/theme.inc --- b/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1721,9 +1721,7 @@ $item = l($link['title'], $link['href'], $link); } else { - if (empty($link['route_parameters'])) { - $link['route_parameters'] = array(); - } + $link += array('route_parameters' => array()); $item = \Drupal::l($link['title'], $link['route_name'], $link['route_parameters'], $link); } } diff -u b/core/lib/Drupal/Core/Menu/ContextualLinkInterface.php b/core/lib/Drupal/Core/Menu/ContextualLinkInterface.php --- b/core/lib/Drupal/Core/Menu/ContextualLinkInterface.php +++ b/core/lib/Drupal/Core/Menu/ContextualLinkInterface.php @@ -36,12 +36,10 @@ /** * 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. + * A contextual link group is a set of contextual links that are displayed + * together on a certain page. For example, the 'block' group displays all + * links related to the block, such as the block instance edit link as well as + * the views edit link, if it is a view block. * * @return string * The contextual links group name. @@ -49,16 +47,20 @@ public function getGroup(); /** - * Returns the options based to the link generator. + * Returns the link options passed to the link generator. * * @return array * The options as expected by LinkGeneratorInterface::generate() + * + * @see \Drupal\Core\Utility\LinkGeneratorInterface::generate() */ public function getOptions(); /** * Returns the weight of the contextual link. * + * The contextual links in one group are sorted by weight for display. + * * @return int * The weight as positive/negative integer. */ diff -u b/core/lib/Drupal/Core/Menu/ContextualLinkManager.php b/core/lib/Drupal/Core/Menu/ContextualLinkManager.php --- b/core/lib/Drupal/Core/Menu/ContextualLinkManager.php +++ b/core/lib/Drupal/Core/Menu/ContextualLinkManager.php @@ -23,7 +23,7 @@ * * @see \Drupal\Core\Menu\ContextualLinkInterface */ -class ContextualLinkManager extends DefaultPluginManager { +class ContextualLinkManager extends DefaultPluginManager implements ContextualLinkManagerInterface { /** * Provides default values for a contextual link definition. @@ -103,13 +103,7 @@ } /** - * Gets the contextual link plugins by contextual link group. - * - * @param string $group_name - * The group name. - * - * @return array - * A list of contextual links plugin definitions. + * {@inheritdoc} */ public function getContextualLinkPluginsByGroup($group_name) { if ($cache = $this->cacheBackend->get($this->cacheKey . ':' . $group_name)) { @@ -128,26 +122,7 @@ } /** - * Gets the contextual links prepared as expected by theme_links(). - * - * @param string $group_name - * The group name. - * @param array $route_parameters - * The incoming route parameters. The route parameters need to have the same - * name on all contextual link routes, e.g. you cannot use node and entity - * in parallel. - * @param array $metadata - * Additional metadata of contextual links, like the position (optional). - * - * @return array - * A list of links as array, keyed by the plugin ID. Each entry is an - * associative array with the following keys: - * - route_name: The route name to link to. - * - route_parameters: The route parameters for the contextual link. - * - title: The title of the contextual link. - * - weight: The weight of the contextual link. - * - localized_options: The options of the link, which will be passed - * to the link generator. + * {@inheritdoc} */ public function getContextualLinksArrayByGroup($group_name, array $route_parameters, array $metadata = array()) { $links = array(); diff -u b/core/modules/content_translation/content_translation.contextual_links.yml b/core/modules/content_translation/content_translation.contextual_links.yml --- b/core/modules/content_translation/content_translation.contextual_links.yml +++ b/core/modules/content_translation/content_translation.contextual_links.yml @@ -3 +3 @@ - weight: 100 + weight: 2 diff -u b/core/modules/contextual/contextual.module b/core/modules/contextual/contextual.module --- b/core/modules/contextual/contextual.module +++ b/core/modules/contextual/contextual.module @@ -238,7 +238,10 @@ * * @param $element * A renderable array containing a #contextual_links property, which is a - * keyed array. Each key is the string "$implementing_module:$group". + * keyed array. Each key is the string "$implementing_module:$group". The + * value contains an associative array containing the following keys: + * - route_parameters: The route parameters passed to the url generator. + * - metadata: Some additional data needed in order to alter the link. * @code * array('#contextual_links' => array( * 'block.block' => array( @@ -334,7 +337,7 @@ * - menu:menu:menu=tools:|block:block:block=bartik.tools: * * So, expressed in a pattern: - * ::: + * ::: * * The route parameters and options are encoded as query strings. * diff -u b/core/modules/node/node.module b/core/modules/node/node.module --- b/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -979,14 +979,7 @@ 'title' => 'Edit', 'route_name' => 'node.page_edit', 'type' => MENU_LOCAL_TASK, - 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, - ); - $items['node/%node/delete'] = array( - 'title' => 'Delete', - 'route_name' => 'node.delete_confirm', - 'weight' => 10, - 'type' => MENU_LOCAL_TASK, - 'context' => MENU_CONTEXT_INLINE, + 'context' => MENU_CONTEXT_PAGE, ); $items['node/%node/revisions'] = array( 'title' => 'Revisions', @@ -1027,7 +1020,14 @@ 'title' => 'Edit', 'route_name' => 'node.page_edit', 'type' => MENU_LOCAL_TASK, - 'context' => MENU_CONTEXT_PAGE, + 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, + ); + $items['node/%node/delete'] = array( + 'title' => 'Delete', + 'route_name' => 'node.delete_confirm', + 'weight' => 10, + 'type' => MENU_LOCAL_TASK, + 'context' => MENU_CONTEXT_INLINE, ); $items['node/%node/revisions'] = array( 'title' => 'Revisions', diff -u b/core/modules/system/system.api.php b/core/modules/system/system.api.php --- b/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -847,11 +847,13 @@ * The system-determined contextual links are passed in by reference. Additional * links may be added and existing links can be altered. * - * Each contextual link must contain at least: + * Each contextual link contains the following entries: * - title: The localized title of the link. * - route_name: The route name of the link. * - route_parameters: The route parameters of the link. * - localized_options: An array of options to pass to url(). + * - (optional) weight: The weight of the link, which is used to sort the links. + * * * @param array $links * An associative array containing contextual links for the given $group, diff -u b/core/modules/system/tests/modules/menu_test/menu_test.contextual_links.yml b/core/modules/system/tests/modules/menu_test/menu_test.contextual_links.yml --- b/core/modules/system/tests/modules/menu_test/menu_test.contextual_links.yml +++ b/core/modules/system/tests/modules/menu_test/menu_test.contextual_links.yml @@ -3,7 +3,7 @@ group: menu_test_menu route_name: menu_test.hidden_manage -menu_test.hidden_manage: +menu_test.hidden_manage_edit: title: 'Edit menu' group: menu_test_menu route_name: menu_test.hidden_manage_edit only in patch2: unchanged: --- /dev/null +++ b/core/lib/Drupal/Core/Menu/ContextualLinkManagerInterface.php @@ -0,0 +1,49 @@ +