Commit 26cf8a2b authored by catch's avatar catch

Issue #1919926 by larowlan, sun: Fixed Simplify custom_block_menu_local_tasks_alter().

parent 780b4392
...@@ -149,8 +149,12 @@ function block_menu() { ...@@ -149,8 +149,12 @@ function block_menu() {
'context' => MENU_CONTEXT_NONE, 'context' => MENU_CONTEXT_NONE,
'file' => 'block.admin.inc', 'file' => 'block.admin.inc',
); );
// Block administration is actually tied to theme and plugin definition so // Block administration is tied to the theme and plugin definition so
// that the plugin can appropriately attach to this url structure. // 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(); $themes = list_themes();
foreach (drupal_container()->get('plugin.manager.system.plugin_ui')->getDefinitions() as $plugin_id => $plugin) { foreach (drupal_container()->get('plugin.manager.system.plugin_ui')->getDefinitions() as $plugin_id => $plugin) {
list($plugin_base, $key) = explode(':', $plugin_id); list($plugin_base, $key) = explode(':', $plugin_id);
......
...@@ -11,33 +11,20 @@ ...@@ -11,33 +11,20 @@
use Drupal\block\Plugin\Core\Entity\Block; 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) { function custom_block_menu_local_tasks(&$data, $router_item, $root_path) {
// Make sure we're at least in the right general area. // Add the "Add custom block" action link to the theme-specific block library
if (substr($root_path, 0, 26) == 'admin/structure/block/list') { // listing page.
// This is the path we want to match. // @todo This should just be $root_path == 'admin/structure/block/list/%/add'
$admin_path = array( // but block_menu() registers static router paths instead of dynamic ones.
'admin', if (preg_match('@^admin/structure/block/list/(.*)/add$@', $root_path)) {
'structure', $item = menu_get_item('block/add');
'block', if ($item['access']) {
'list', $data['actions']['block/add'] = array(
'add', '#theme' => 'menu_local_action',
); '#link' => $item,
// 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,
);
}
} }
} }
} }
...@@ -46,7 +33,6 @@ function custom_block_menu_local_tasks_alter(&$data, $router_item, $root_path) { ...@@ -46,7 +33,6 @@ function custom_block_menu_local_tasks_alter(&$data, $router_item, $root_path) {
* Implements hook_menu(). * Implements hook_menu().
*/ */
function custom_block_menu() { function custom_block_menu() {
$items = array();
$items['admin/structure/custom-blocks'] = array( $items['admin/structure/custom-blocks'] = array(
'title' => 'Custom block types', 'title' => 'Custom block types',
'description' => 'Manage custom block types.', 'description' => 'Manage custom block types.',
...@@ -92,7 +78,6 @@ function custom_block_menu() { ...@@ -92,7 +78,6 @@ function custom_block_menu() {
'access arguments' => array('administer blocks'), 'access arguments' => array('administer blocks'),
'file' => 'custom_block.pages.inc', 'file' => 'custom_block.pages.inc',
); );
$items['block/add/%custom_block_type'] = array( $items['block/add/%custom_block_type'] = array(
'title callback' => 'entity_page_label', 'title callback' => 'entity_page_label',
'title arguments' => array(2), 'title arguments' => array(2),
......
...@@ -77,6 +77,10 @@ public function testCustomBlock() { ...@@ -77,6 +77,10 @@ public function testCustomBlock() {
$this->drupalGet("admin/structure/block/list/block_plugin_ui:$default_theme/add"); $this->drupalGet("admin/structure/block/list/block_plugin_ui:$default_theme/add");
$this->assertLink(t('Add custom block')); $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 // Confirm that hidden regions are not shown as options for block placement
// when adding a new block. // when adding a new block.
theme_enable(array('bartik')); theme_enable(array('bartik'));
......
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