Commit b469334d authored by catch's avatar catch

Issue #2100073 by dawehner: Convert local_actions() to the new local action plugins.

parent c33315da
......@@ -387,7 +387,7 @@ services:
arguments: ['@http_kernel', '@controller_resolver', '@string_translation', '@title_resolver']
controller.dialog:
class: Drupal\Core\Controller\DialogController
arguments: ['@http_kernel']
arguments: ['@http_kernel', '@title_resolver']
router_listener:
class: Symfony\Component\HttpKernel\EventListener\RouterListener
tags:
......
......@@ -149,11 +149,6 @@
*/
const MENU_IS_LOCAL_TASK = 0x0080;
/**
* Internal menu flag -- menu item is a local action.
*/
const MENU_IS_LOCAL_ACTION = 0x0100;
/**
* @} End of "defgroup menu_flags".
*/
......@@ -211,21 +206,13 @@
*/
define('MENU_DEFAULT_LOCAL_TASK', MENU_IS_LOCAL_TASK | MENU_LINKS_TO_PARENT | MENU_VISIBLE_IN_BREADCRUMB);
/**
* Menu type -- An action specific to the parent, usually rendered as a link.
*
* Local actions are menu items that describe actions on the parent item such
* as adding a new user, taxonomy term, etc.
*/
define('MENU_LOCAL_ACTION', MENU_IS_LOCAL_TASK | MENU_IS_LOCAL_ACTION | MENU_VISIBLE_IN_BREADCRUMB);
/**
* Menu type -- A task specific to the parent, which is never rendered.
*
* Sibling local tasks are not rendered themselves, but affect the active
* trail and need their sibling tasks rendered as tabs.
*/
define('MENU_SIBLING_LOCAL_TASK', MENU_IS_LOCAL_TASK | MENU_IS_LOCAL_ACTION | MENU_VISIBLE_IN_BREADCRUMB);
define('MENU_SIBLING_LOCAL_TASK', MENU_IS_LOCAL_TASK | MENU_VISIBLE_IN_BREADCRUMB);
/**
* @} End of "defgroup menu_item_types".
......@@ -2117,27 +2104,12 @@ function _menu_get_legacy_tasks($router_item, &$data, &$root_path) {
$tab_count++;
}
else {
// Actions can be normal items too, so bitmask with
// MENU_IS_LOCAL_ACTION before checking.
if (($item['type'] & MENU_IS_LOCAL_ACTION) == MENU_IS_LOCAL_ACTION) {
// The item is an action, display it as such.
$key = isset($link['route_name']) ? $link['route_name'] : $link['href'];
$actions_current[$key] = array(
'#theme' => 'menu_local_action',
'#link' => $link,
'#weight' => isset($link['weight']) ? $link['weight'] : NULL,
);
$action_count++;
}
else {
// Otherwise, it's a normal tab.
$tabs_current[$link['href']] = array(
'#theme' => 'menu_local_task',
'#link' => $link,
'#weight' => isset($link['weight']) ? $link['weight'] : NULL,
);
$tab_count++;
}
$tabs_current[$link['href']] = array(
'#theme' => 'menu_local_task',
'#link' => $link,
'#weight' => isset($link['weight']) ? $link['weight'] : NULL,
);
$tab_count++;
}
}
}
......@@ -2158,10 +2130,6 @@ function _menu_get_legacy_tasks($router_item, &$data, &$root_path) {
$next_parent = '';
$count = 0;
foreach ($children[$parent] as $item) {
// Skip local actions.
if ($item['type'] & MENU_IS_LOCAL_ACTION) {
continue;
}
if ($item['access']) {
$count++;
$link = $item;
......
......@@ -25,14 +25,24 @@ class DialogController {
*/
protected $httpKernel;
/**
* The title resolver.
*
* @var \Drupal\Core\Controller\TitleResolver
*/
protected $titleResolver;
/**
* Constructs a new DialogController.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $kernel
* The kernel.
* @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver
* The title resolver.
*/
public function __construct(HttpKernelInterface $kernel) {
public function __construct(HttpKernelInterface $kernel, TitleResolverInterface $title_resolver) {
$this->httpKernel = $kernel;
$this->titleResolver = $title_resolver;
}
/**
......@@ -94,9 +104,11 @@ public function dialog(Request $request, $modal = FALSE) {
$subrequest = $this->forward($request);
if ($subrequest->isOk()) {
$content = $subrequest->getContent();
// @todo Remove use of drupal_get_title() when
// http://drupal.org/node/1871596 is in.
$title = drupal_get_title();
if (!$title = $this->titleResolver->getTitle($request, $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT))) {
// @todo Remove use of drupal_get_title() when
// http://drupal.org/node/1871596 is in.
$title = drupal_get_title();
}
$response = new AjaxResponse();
// Fetch any modal options passed in from data-dialog-options.
if (!($options = $request->request->get('dialogOptions'))) {
......
aggregator.feed_add:
route_name: aggregator.feed_add
title: 'Add feed'
appears_on:
- 'aggregator.admin_overview'
aggregator.category_add:
route_name: aggregator.category_add
title: 'Add category'
appears_on:
- 'aggregator.admin_overview'
aggregator.opml_add:
route_name: aggregator.opml_add
title: 'Import OPML'
appears_on:
- 'aggregator.admin_overview'
......@@ -97,21 +97,6 @@ function aggregator_menu() {
'route_name' => 'aggregator.admin_overview',
'weight' => 10,
);
$items['admin/config/services/aggregator/add/feed'] = array(
'title' => 'Add feed',
'route_name' => 'aggregator.feed_add',
'type' => MENU_LOCAL_ACTION,
);
$items['admin/config/services/aggregator/add/category'] = array(
'title' => 'Add category',
'type' => MENU_LOCAL_ACTION,
'route_name' => 'aggregator.category_add',
);
$items['admin/config/services/aggregator/add/opml'] = array(
'title' => 'Import OPML',
'type' => MENU_LOCAL_ACTION,
'route_name' => 'aggregator.opml_add',
);
$items['admin/config/services/aggregator/remove/%aggregator_feed'] = array(
'title' => 'Remove items',
'route_name' => 'aggregator.feed_items_delete',
......
contact.category_add:
route_name: contact.category_add
title: 'Add category'
weight: 1
appears_on:
- contact.category_list
......@@ -63,12 +63,6 @@ function contact_menu() {
'description' => 'Create a system contact form and set up categories for the form to use.',
'route_name' => 'contact.category_list',
);
$items['admin/structure/contact/add'] = array(
'title' => 'Add category',
'route_name' => 'contact.category_add',
'type' => MENU_LOCAL_ACTION,
'weight' => 1,
);
$items['admin/structure/contact/manage/%contact_category'] = array(
'title' => 'Edit contact category',
'route_name' => 'contact.category_edit',
......
......@@ -17,6 +17,7 @@ contact.category_add:
path: '/admin/structure/contact/add'
defaults:
_entity_form: contact_category.add
_title: 'Add category'
requirements:
_permission: 'administer contact forms'
......
......@@ -3,3 +3,9 @@ menu_link_add:
title: 'Add link'
appears_on:
- menu.menu_edit
menu.menu_add:
route_name: menu.menu_add
title: 'Add menu'
appears_on:
- menu.overview_page
......@@ -74,11 +74,6 @@ function menu_menu() {
'title' => 'List menus',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/structure/menu/add'] = array(
'title' => 'Add menu',
'route_name' => 'menu.menu_add',
'type' => MENU_LOCAL_ACTION,
);
$items['admin/structure/menu/settings'] = array(
'title' => 'Settings',
'route_name' => 'menu.settings',
......
node.type_add:
route_name: node.type_add
title: 'Add content type'
appears_on:
- node.overview_types
......@@ -949,11 +949,6 @@ function node_menu() {
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/structure/types/add'] = array(
'title' => 'Add content type',
'route_name' => 'node.type_add',
'type' => MENU_LOCAL_ACTION,
);
$items['admin/structure/types/manage/%node_type'] = array(
'title' => 'Edit content type',
'title callback' => 'entity_page_label',
......
path.admin_add:
route_name: path.admin_add
title: 'Add alias'
appears_on:
- path.admin_overview
......@@ -74,11 +74,6 @@ function path_menu() {
'title' => 'Delete alias',
'route_name' => 'path.delete',
);
$items['admin/config/search/path/add'] = array(
'title' => 'Add alias',
'route_name' => 'path.admin_add',
'type' => MENU_LOCAL_ACTION,
);
return $items;
}
......
picture.mapping_page_add:
route_name: picture.mapping_page_add
title: 'Add picture mapping'
appears_on:
- picture.mapping_page
......@@ -59,11 +59,6 @@ function picture_menu() {
'weight' => 10,
'route_name' => 'picture.mapping_page',
);
$items['admin/config/media/picturemapping/add'] = array(
'title' => 'Add picture mapping',
'route_name' => 'picture.mapping_page_add',
'type' => MENU_LOCAL_ACTION,
);
$items['admin/config/media/picturemapping/%picture_mapping'] = array(
'title' => 'Edit picture mapping',
'route_name' => 'picture.mapping_page_edit',
......
......@@ -3,3 +3,8 @@ shortcut_set_add_local_action:
title: 'Add shortcut set'
appears_on:
- shortcut.set_admin
shortcut.link_add:
route_name: shortcut.link_add
title: 'Add shortcut'
appears_on:
- shortcut.set_customize
......@@ -106,11 +106,6 @@ function shortcut_menu() {
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
$items['admin/config/user-interface/shortcut/manage/%shortcut_set/add-link'] = array(
'title' => 'Add shortcut',
'route_name' => 'shortcut.link_edit',
'type' => MENU_LOCAL_ACTION,
);
$items['admin/config/user-interface/shortcut/link/%menu_link'] = array(
'title' => 'Edit shortcut',
'route_name' => 'shortcut.link_edit',
......
......@@ -92,13 +92,13 @@ public function access(AccountInterface $account) {
*/
protected function getActiveHelp(Request $request) {
$output = '';
$router_path = menu_tab_root_path();
$router_path = $request->attributes->get('_system_path');
// We will always have a path unless we are on a 403 or 404.
if (!$router_path) {
return '';
}
$arg = drupal_help_arg(explode('/', $request->attributes->get('_system_path')));
$arg = drupal_help_arg(explode('/', $router_path));
foreach ($this->moduleHandler->getImplementations('help') as $module) {
$function = $module . '_help';
......
......@@ -68,7 +68,7 @@ public function testDialog() {
'settings' => NULL,
'dialogOptions' => array(
'modal' => TRUE,
'title' => 'Home',
'title' => 'Add category',
),
);
$normal_expected_response = array(
......
......@@ -37,8 +37,8 @@ public function testLocalAction() {
$this->drupalGet('menu-test-local-action');
// Ensure that both menu and route based actions are shown.
$this->assertLocalAction(array(
'menu-test-local-action/hook_menu' => 'My hook_menu action',
'menu-test-local-action/dynamic-title' => 'My dynamic-title action',
'menu-test-local-action/hook_menu' => 'My hook_menu action',
'menu-test-local-action/routing' => 'My YAML discovery action',
'menu-test-local-action/routing2' => 'Title override',
));
......
......@@ -232,10 +232,6 @@ protected function doTestMenuHidden() {
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/menu/add'];
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/menu/settings'];
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
......@@ -252,10 +248,6 @@ protected function doTestMenuHidden() {
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/menu/manage/%/add'];
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/menu/manage/%/edit'];
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
......@@ -284,10 +276,6 @@ protected function doTestMenuHidden() {
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/block/add'];
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/block/manage/%/%'];
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
......
system.date_format_add:
route_name: system.date_format_add
title: 'Add format'
weight: -10
appears_on:
- system.date_format_list
......@@ -736,13 +736,6 @@ function system_menu() {
'route_name' => 'system.date_format_list',
'weight' => -9,
);
$items['admin/config/regional/date-time/formats/add'] = array(
'title' => 'Add format',
'description' => 'Allow users to add additional date formats.',
'type' => MENU_LOCAL_ACTION,
'route_name' => 'system.date_format_add',
'weight' => -10,
);
$items['admin/config/regional/date-time/formats/manage/%'] = array(
'title' => 'Edit date format',
'description' => 'Allow users to edit a configured date format.',
......
<?php
/**
* @file
* Contains \Drupal\menu_test\Plugin\Menu\LocalAction\TestLocalAction4.
*/
namespace Drupal\menu_test\Plugin\Menu\LocalAction;
use Drupal\Core\Menu\LocalActionDefault;
/**
* Defines a local action plugin with a dynamic title.
*/
class TestLocalAction4 extends LocalActionDefault {
/**
* {@inheritdoc}
*/
public function getTitle() {
return $this->t('My @arg action', array('@arg' => 'dynamic-title'));
}
}
......@@ -11,3 +11,35 @@ menu_test.local_action5:
appears_on:
- menu_test.local_action1
menu_test.local_action2:
route_name: menu_test.local_action2
title: 'My hook_menu action'
weight: -10
appears_on:
- menu_test.local_action1
menu_test.local_action4:
route_name: menu_test.local_action4
title: 'My dynamic title action'
weight: -20
class: '\Drupal\menu_test\Plugin\Menu\LocalAction\TestLocalAction4'
appears_on:
- menu_test.local_action1
menu_test.hidden_menu_add:
route_name: menu_test.hidden_menu_add
title: 'Add menu'
appears_on:
- menu_test.hidden_menu
menu_test.hidden_manage_add:
route_name: menu_test.hidden_manage_add
title: 'Add link'
appears_on:
- menu_test.hidden_manage
menu_test.hidden_block_add:
route_name: menu_test.hidden_block_add
title: 'Add block'
appears_on:
- menu_test.hidden_block
......@@ -108,11 +108,6 @@ function menu_test_menu() {
'title' => 'List menus',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['menu-test/hidden/menu/add'] = array(
'title' => 'Add menu',
'route_name' => 'menu_test.hidden_menu_add',
'type' => MENU_LOCAL_ACTION,
);
$items['menu-test/hidden/menu/settings'] = array(
'title' => 'Settings',
'route_name' => 'menu_test.hidden_menu_settings',
......@@ -128,11 +123,6 @@ function menu_test_menu() {
'type' => MENU_DEFAULT_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE,
);
$items['menu-test/hidden/menu/manage/%menu/add'] = array(
'title' => 'Add link',
'route_name' => 'menu_test.hidden_manage_add',
'type' => MENU_LOCAL_ACTION,
);
$items['menu-test/hidden/menu/manage/%menu/edit'] = array(
'title' => 'Edit menu',
'route_name' => 'menu_test.hidden_manage_edit',
......@@ -153,11 +143,6 @@ function menu_test_menu() {
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['menu-test/hidden/block/add'] = array(
'title' => 'Add block',
'route_name' => 'menu_test.hidden_block_add',
'type' => MENU_LOCAL_ACTION,
);
$items['menu-test/hidden/block/manage/%/%'] = array(
'title' => 'Configure block',
'route_name' => 'menu_test.hidden_block_configure',
......@@ -298,22 +283,6 @@ function menu_test_menu() {
'route_name' => 'menu_test.local_action1',
);
$items['menu-test-local-action/hook_menu'] = array(
'title' => 'My hook_menu action',
'route_name' => 'menu_test.local_action2',
'weight' => -10,
'type' => MENU_LOCAL_ACTION,
);
$items['menu-test-local-action/dynamic-title'] = array(
'title' => 'My dynamic title action',
'title callback' => 'menu_test_local_action_dynamic_title',
'title arguments' => array(1),
'route_name' => 'menu_test.local_action4',
'weight' => -10,
'type' => MENU_LOCAL_ACTION,
);
$items['menu-local-task-test/tasks'] = array(
'title' => 'Local tasks',
'route_name' => 'menu_test.local_task_test_tasks',
......@@ -327,13 +296,6 @@ function menu_test_menu() {
return $items;
}
/**
* Title callback: Set a dynamic title for a local action.
*/
function menu_test_local_action_dynamic_title($arg) {
return t('My @arg action', array('@arg' => $arg));
}
/**
* Implements hook_menu_local_tasks().
*
......
......@@ -3,3 +3,9 @@ taxonomy_add_vocabulary_local_action:
title: 'Add vocabulary'
appears_on:
- taxonomy.vocabulary_list
taxonomy.term_add:
route_name: taxonomy.term_add
title: 'Add term'
appears_on:
- taxonomy.overview_terms
......@@ -278,12 +278,6 @@ function taxonomy_menu() {
'type' => MENU_LOCAL_TASK,
);
$items['admin/structure/taxonomy/manage/%taxonomy_vocabulary/add'] = array(
'title' => 'Add term',
'route_name' => 'taxonomy.term_add',
'type' => MENU_LOCAL_ACTION,
);
return $items;
}
......
......@@ -242,4 +242,25 @@ protected function setSystemInfo7_0() {
);
\Drupal::config('update_test.settings')->set('system_info', $setting)->save();
}
/**
* Ensures that the local actions appear.
*/
public function testLocalActions() {
$admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer modules', 'administer software updates', 'administer themes'));
$this->drupalLogin($admin_user);
$this->drupalGet('admin/modules');
$this->clickLink(t('Install new module'));
$this->assertUrl('admin/modules/install');
$this->drupalGet('admin/appearance');
$this->clickLink(t('Install new theme'));
$this->assertUrl('admin/theme/install');
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Install new module or theme'));
$this->assertUrl('admin/reports/updates/install');
}
}
update.report_install:
route_name: update.report_install
title: 'Install new module or theme'
weight: 25
appears_on:
- update.status
update.module_install:
route_name: update.module_install
title: 'Install new module'
weight: 25
appears_on:
- system.modules_list
update.theme_install:
route_name: update.theme_install
title: 'Install new theme'
weight: 25
appears_on:
- system.themes_page
......@@ -157,30 +157,6 @@ function update_menu() {
'weight' => -50,
);
// We want action links for updating projects at a few different locations:
// both the module and theme administration pages, and on the available
// updates report itself. The menu items will be mostly identical, except the
// paths and titles, so we just define them in a loop. We pass in a string
// indicating what context we're entering the action from, so that can
// customize the appearance as needed.
$paths = array(
'report' => 'admin/reports/updates',
'module' => 'admin/modules',
'theme' => 'admin/appearance',
);
foreach ($paths as $context => $path) {
$items[$path . '/install'] = array(
'route_name' => "update.{$context}_install",
'weight' => 25,
'type' => MENU_LOCAL_ACTION,
);
}
// Customize the titles of the action links depending on where they appear.
// We use += array() to let the translation extractor find these menu titles.
$items['admin/reports/updates/install'] += array('title' => 'Install new module or theme');
$items['admin/modules/install'] += array('title' => 'Install new module');
$items['admin/appearance/install'] += array('title' => 'Install new theme');
return $items;
}
......
......@@ -3,3 +3,8 @@ user_admin_create:
title: 'Add user'
appears_on:
- user.admin_account
user.role_add:
route_name: user.role_add
title: 'Add role'
appears_on:
- user.role_list
......@@ -781,11 +781,6 @@ function user_menu() {
'route_name' => 'user.admin_permissions',
'type' => MENU_LOCAL_TASK,
);
$items['admin/people/roles/add'] = array(
'title' => 'Add role',
'route_name' => 'user.role_add',
'type' => MENU_LOCAL_ACTION,
);
$items['admin/people/roles/manage/%user_role'] = array(
'title' => 'Edit role',
......
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