diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 222d09a224966af14bcd52172a58e54a3d3ff421..ff804b24672976d2f131367bbe8c8c7b64d447b9 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -149,8 +149,12 @@ function block_menu() { 'context' => MENU_CONTEXT_NONE, 'file' => 'block.admin.inc', ); - // Block administration is actually tied to theme and plugin definition so - // that the plugin can appropriately attach to this url structure. + // Block administration is tied to the theme and plugin definition so + // that the plugin can appropriately attach to this URL structure. + // @todo D8: Use dynamic % arguments instead of static, hard-coded theme names + // and plugin IDs to decouple the routes from these dependencies and allow + // hook_menu_local_tasks() to check for the untranslated tab_parent path. + // @see http://drupal.org/node/1067408 $themes = list_themes(); foreach (drupal_container()->get('plugin.manager.system.plugin_ui')->getDefinitions() as $plugin_id => $plugin) { list($plugin_base, $key) = explode(':', $plugin_id); diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 83117c8607b7b879e50cbf208d215ec9627102d1..a3ce18c2af0248c401230efc10b211456f8c7e8c 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -11,33 +11,20 @@ use Drupal\block\Plugin\Core\Entity\Block; /** - * Implements hook_menu_local_task_alter(). + * Implements hook_menu_local_tasks(). */ -function custom_block_menu_local_tasks_alter(&$data, $router_item, $root_path) { - // Make sure we're at least in the right general area. - if (substr($root_path, 0, 26) == 'admin/structure/block/list') { - // This is the path we want to match. - $admin_path = array( - 'admin', - 'structure', - 'block', - 'list', - 'add', - ); - // We're going to want an array so we can remove the plugin id. - $path_map = explode('/', $root_path); - $before = array_slice($path_map, 0, 4); - $after = array_slice($path_map, 5); - $path_map = array_merge($before, $after); - // If the path is absolutely equal to $admin_path, we have a winner. - if($path_map === $admin_path) { - $item = menu_get_item('block/add'); - if ($item['access']) { - $data['actions']['output'][] = array( - '#theme' => 'menu_local_action', - '#link' => $item, - ); - } +function custom_block_menu_local_tasks(&$data, $router_item, $root_path) { + // Add the "Add custom block" action link to the theme-specific block library + // listing page. + // @todo This should just be $root_path == 'admin/structure/block/list/%/add' + // but block_menu() registers static router paths instead of dynamic ones. + if (preg_match('@^admin/structure/block/list/(.*)/add$@', $root_path)) { + $item = menu_get_item('block/add'); + if ($item['access']) { + $data['actions']['block/add'] = array( + '#theme' => 'menu_local_action', + '#link' => $item, + ); } } } @@ -46,7 +33,6 @@ function custom_block_menu_local_tasks_alter(&$data, $router_item, $root_path) { * Implements hook_menu(). */ function custom_block_menu() { - $items = array(); $items['admin/structure/custom-blocks'] = array( 'title' => 'Custom block types', 'description' => 'Manage custom block types.', @@ -92,7 +78,6 @@ function custom_block_menu() { 'access arguments' => array('administer blocks'), 'file' => 'custom_block.pages.inc', ); - $items['block/add/%custom_block_type'] = array( 'title callback' => 'entity_page_label', 'title arguments' => array(2), diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index 27dbfa103bd030e91176e916496e6a0d0b4dce1f..38a0d2983208cc478d2bd7ca133dc17af14fd2fa 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -77,6 +77,10 @@ public function testCustomBlock() { $this->drupalGet("admin/structure/block/list/block_plugin_ui:$default_theme/add"); $this->assertLink(t('Add custom block')); + // But not on the normal admin page. + $this->drupalGet('admin/structure/block'); + $this->assertNoLink(t('Add custom block')); + // Confirm that hidden regions are not shown as options for block placement // when adding a new block. theme_enable(array('bartik'));