diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 48528ef..83117c8 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -7,32 +7,46 @@ use Drupal\custom_block\Plugin\Core\Entity\CustomBlockType; use Drupal\custom_block\Plugin\Core\Entity\CustomBlock; -use Symfony\Component\HttpFoundation\RedirectResponse; use Drupal\custom_block\Plugin\block\block\CustomBlockBlock; use Drupal\block\Plugin\Core\Entity\Block; /** - * Implements hook_menu(). + * Implements hook_menu_local_task_alter(). */ -function custom_block_menu() { - $items = array(); - // Add an "Add custom block" action link for each theme. - foreach (drupal_container()->get('plugin.manager.system.plugin_ui')->getDefinitions() as $plugin_id => $plugin) { - // Only add the link for block plugin UI derivatives (that is, per-theme - // block instance configuration). - if (strpos($plugin_id, 'block_plugin_ui') === 0) { - list(, $theme) = explode(':', $plugin_id); - $items['admin/structure/block/list/' . $plugin_id . '/add/custom_blocks'] = array( - 'title' => 'Add custom block', - 'description' => 'Create a block with custom content and settings.', - 'page callback' => 'custom_block_add_block_redirect', - 'page arguments' => array($theme), - 'access arguments' => array('administer blocks'), - 'type' => MENU_LOCAL_ACTION, - ); +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, + ); + } } } +} +/** + * Implements hook_menu(). + */ +function custom_block_menu() { + $items = array(); $items['admin/structure/custom-blocks'] = array( 'title' => 'Custom block types', 'description' => 'Manage custom block types.', @@ -291,17 +305,6 @@ function custom_block_admin_paths() { } /** - * Page callback: Redirect user to the block add page. - * - * @param string $theme - * The theme name for which the newly created custom block will be configured. - */ -function custom_block_add_block_redirect($theme) { - $url = url('block/add', array('query' => array('theme' => $theme))); - return new RedirectResponse($url); -} - -/** * Implements hook_block_view_alter(). */ function custom_block_block_view_alter(array &$build, Block $block) { diff --git a/core/modules/block/custom_block/custom_block.pages.inc b/core/modules/block/custom_block/custom_block.pages.inc index cae286e..439030e 100644 --- a/core/modules/block/custom_block/custom_block.pages.inc +++ b/core/modules/block/custom_block/custom_block.pages.inc @@ -12,13 +12,10 @@ /** * Page callback: Displays add custom block links for available types. * - * Redirects to block/add/[type] if only one custom block type is available. - * * @return array - * A render array for a list of the custom block types that can be added; - * however, if there is only one custom block type defined for the site, the - * function redirects to the custom block add page for that one custom block - * type and does not return at all. + * A render array for a list of the custom block types that can be added or + * if there is only one custom block type defined for the site, the function + * returns the custom block add page for that custom block type. * * @see custom_block_menu() */ @@ -36,8 +33,7 @@ function custom_block_add_page() { $types = entity_load_multiple('custom_block_type'); if ($types && count($types) == 1) { $type = reset($types); - $url = url('block/add/' . $type->id(), $options); - return new RedirectResponse($url); + return custom_block_add($type); } return array('#theme' => 'custom_block_add_list', '#content' => $types); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php index 047c1cd..ba86c1b 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php @@ -39,7 +39,6 @@ public static function getInfo() { */ protected function setUp() { parent::setUp(); - $this->drupalLogin($this->adminUser); } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockRevisionsTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockRevisionsTest.php index 1ff17f4..b1d1220 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockRevisionsTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockRevisionsTest.php @@ -99,5 +99,5 @@ public function testRevisions() { $default_revision = entity_load('custom_block', $loaded->id->value); $this->assertTrue($loaded->revision_id->value > $default_revision->revision_id->value, 'Revision id is greater than default revision id.'); } - + } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockSaveTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockSaveTest.php index 26fe185..1874ff3 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockSaveTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockSaveTest.php @@ -107,5 +107,5 @@ public function testCustomBlockSaveOnInsert() { $block = $this->createCustomBlock('new'); $this->assertEqual($block->label(), 'CustomBlock ' . $block->id->value, 'Custom block saved on block insert.'); } - + }