Follow up for #1871772-108: Convert custom blocks to content entities

Problem/Motivation

+++ b/core/modules/block/custom_block/custom_block.module
@@ -5,29 +5,129 @@
+function custom_block_menu_local_tasks_alter(&$data, $router_item, $root_path) {
...
+ if (substr($root_path, 0, 26) == 'admin/structure/block/list') {
...
+ $path_map = explode('/', $root_path);
I just left some remarks in IRC that this implementation of hook_menu_local_tasks_alter() is one of the most complex I've ever seen and that I'm absolutely confident that it can be vastly simplified.

But that's straight refactoring/simplification, so can happen later. :)

That said, in case #1864066: Simplify hook_menu_local_tasks() and MENU_DEFAULT_LOCAL_TASK usage will land first, this hook needs to be adjusted to be not an alter hook, since it adds a local task (instead of altering an existing).

Proposed resolution

Refactor custom_block_menu_local_tasks_alter() once #1864066: Simplify hook_menu_local_tasks() and MENU_DEFAULT_LOCAL_TASK usage lands

Remaining tasks

Write patch

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Category: task » bug
Status: Postponed » Active
Issue tags: -Entity system, -D8 upgrade path

Since #1864066: Simplify hook_menu_local_tasks() and MENU_DEFAULT_LOCAL_TASK usage landed in parallel, the current code is definitely broken, as the structure of $data was changed, too.

larowlan’s picture

Assigned: Unassigned » larowlan

working on it now

larowlan’s picture

Refactors to use hook_menu_local_tasks() and removes a lot of the logic in favour of preg_match().
Shot from seven (shown as expected)
Screen Shot 2013-02-19 at 4.15.01 PM.png
Shot from bartik (Default theme) (shown as expected)
Screen Shot 2013-02-19 at 4.15.17 PM.png
Shot from other items with same tab root (not shown as expected)
Screen Shot 2013-02-19 at 4.15.24 PM.png

We already had tests for the presence of the link.
Added another to make sure it doesn't show up on other items under tab root.

larowlan’s picture

Assigned: larowlan » Unassigned
sun’s picture

+++ b/core/modules/block/custom_block/custom_block.module
@@ -11,33 +11,17 @@
   // Make sure we're at least in the right general area.
...
+  if (preg_match('@^admin/structure/block/list/(.*)/add$@', $root_path)) {

This still looks a bit too complex to me.

Can you clarify which exact paths we're trying to match? And which ones we don't want to match?

larowlan’s picture

Hey @sun

admin/structure/block/list/block_plugin_ui%3Abartik/add
admin/structure/block/list/block_plugin_ui%3Aseven/add
admin/structure/block/list/block_plugin_ui%3Astark/add

Basically admin/structure/block/list/block_plugin_ui:$theme_name/add for any theme name

sun’s picture

OK, now I understand what's going on. I've added @todos to clarify why this is unnecessarily complex.

For now I referenced #1067408: Themes do not have an installation status since one of its changes is to resolve exactly this. However, we might want to create a separate, dedicated issue for this.

I also removed the 'output' subkey in the returned action array, since that is no longer needed due to #1864066: Simplify hook_menu_local_tasks() and MENU_DEFAULT_LOCAL_TASK usage

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

This is RTBC if bot comes back green.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Looks fine. Committed/pushed to 8.x.

Automatically closed -- issue fixed for 2 weeks with no activity.