Use proper menu router paths for the block module (but no argument loader functions)

David_Rothstein - October 16, 2009 - 17:52
Project:Drupal
Version:7.x-dev
Component:block.module
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

As per #473268: D7UX: Put edit links on everything -- and see also #606608: Use proper menu router paths for comment/* -- but actually a good cleanup in its own right.

Block module defines these two router items:

<?php
  $items
['admin/structure/block/configure'] = array(
   
'title' => 'Configure block',
   
'page callback' => 'drupal_get_form',
   
'page arguments' => array('block_admin_configure'),
   
'access arguments' => array('administer blocks'),
   
'type' => MENU_CALLBACK,
   
'file' => 'block.admin.inc',
  );
 
$items['admin/structure/block/delete'] = array(
   
'title' => 'Delete block',
   
'page callback' => 'drupal_get_form',
   
'page arguments' => array('block_custom_block_delete'),
   
'access arguments' => array('administer blocks'),
   
'type' => MENU_CALLBACK,
   
'file' => 'block.admin.inc',
  );
?>

Then, in the page callback function, it searches for the (undeclared) 5th and 6th parameters in the URL, which are the block module and delta to be configured/deleted.

For proper consistency, we need to rename these URLs to follow the more standard Drupal pattern, e.g. something like:

admin/structure/block/manage/%/%/configure
admin/structure/block/manage/%/%/delete

Note that I added "manage" as one of the URL parameters to avoid possible conflicts with other URLs in the module (e.g. admin/structure/block/list).

#1

sun - October 16, 2009 - 17:55

#2

sun - October 16, 2009 - 17:55

#3

eojthebrave - October 16, 2009 - 19:15
Status:active» needs review

Lets see how the bot likes this.

AttachmentSizeStatusTest resultOperations
606640-3-eojthebrave-block_router_paths.patch19.25 KBIdleFailed: Failed to apply patch.View details | Re-test

#4

sun - October 16, 2009 - 19:27

+++ modules/block/block.module
@@ -95,18 +95,18 @@ function block_menu() {
+  $items['admin/structure/block/manage/%/%/configure'] = array(
...
     'type' => MENU_CALLBACK,
...
+  $items['admin/structure/block/manage/%/delete'] = array(
...
     'type' => MENU_CALLBACK,

We should convert these into local tasks already.

I originally envisioned to use

admin/structure/block/manage/%block/%/configure

here, along with a

'load arguments' => array(5),

and introduce a new

function block_load($module, $delta)

that loads and returns the $block from the DB.

Not sure whether that complicates things...

Aside from that, this patch looks pretty straightforward.

I'm on crack. Are you, too?

#5

David_Rothstein - October 16, 2009 - 19:33

I'm not the bot, but it looks pretty good to me :)

-  $items['admin/structure/block/delete'] = array(
+  $items['admin/structure/block/manage/%/delete'] = array(
     'title' => 'Delete block',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('block_custom_block_delete'),
+    'page arguments' => array('block_custom_block_delete', 4, 5),

Looks like there's an inconsistency here (you're passing an extra parameter to the page callback). Actually, I missed the distinction while writing the above issue (that this path only applies to custom blocks).... I wonder if we should actually rename this url to 'admin/structure/block/manage/block/%/delete' in that case?

A minor thing: The function signatures are currently:

function block_custom_block_delete($form, &$form_state, $bid = 0) {
function block_admin_configure($form, &$form_state, $module = NULL, $delta = 0) {

Seems like the latter parameters should no longer be optional, now that we're using the menu system? (Actually it may have never made sense before that way either, in which case this can be dealt with later.)

#6

effulgentsia - October 16, 2009 - 19:34

@sun: why "%block/%"? Any reason not to use the unique bid for loading %block, and then from the block object, the page callback would have access to both 'module' and 'delta'?

#7

David_Rothstein - October 16, 2009 - 19:35

and introduce a new

function block_load($module, $delta)

that loads and returns the $block from the DB.

Not sure whether that complicates things...

Seems like it might complicate... note that the two callbacks require different things here (one needs stuff from the block_custom table, one doesn't), so maybe better to not make that change in this issue?

#8

David_Rothstein - October 16, 2009 - 19:52

Any reason not to use the unique bid for loading %block, and then from the block object, the page callback would have access to both 'module' and 'delta'?

I think there are some places where we might need to construct these URLs but don't know the bid offhand (but already know the module/delta), so this would probably complicate the code in those places.... plus, the URLs would be less meaningful.

I'd vote for sticking with "%/%" to keep this patch as simple as possible :)

#9

effulgentsia - October 16, 2009 - 19:58

Furthermore, if we start using .../BID/configure instead of .../MODULE/DELTA/configure, then we can get rid of the word "manage" from the path, because a BID is always an integer. So we would just have /admin/structure/block/BID/configure (and delete), making it more like nodes and comments.

@eojthebrave: note also, http://drupal.org/node/606608#comment-2159830. probably same should apply in this patch if converting to local tasks.

#10

effulgentsia - October 16, 2009 - 20:02

oops. cross-posted with David. Never mind then. However, a helper function block_get_bid(module, delta) would be pretty trivial to write if the benefits were assumed to be worth it. I'm fine with the idea of KISS though, given that we're technically past API freeze.

#11

eojthebrave - October 16, 2009 - 20:15

Now uses %block and block_load.

Changed path for delete to .../manage/block//delete

Changed block/configure to MENU_LOCAL_TASK, but not block/delete since this causes every block to get a delete tab, but it only applies to custom blocks.

@effulgenstia, while I totally agree that we should get rid of the module/delta paths lets leave that to another issue. Something like #430886: Make custom blocks fieldable

AttachmentSizeStatusTest resultOperations
606640-11-eojthebrave-block_router_paths.patch26.9 KBIdleFailed: 13246 passes, 12 fails, 0 exceptionsView details | Re-test

#12

eojthebrave - October 16, 2009 - 20:26

Extra white space removed.

AttachmentSizeStatusTest resultOperations
606640-12-eojthebrave-block_router_paths.patch26.9 KBIdleFailed: 13239 passes, 12 fails, 0 exceptionsView details | Re-test

#13

System Message - October 16, 2009 - 20:45
Status:needs review» needs work

The last submitted patch failed testing.

#14

eojthebrave - October 16, 2009 - 21:26

Should fix test.

Also, changed MENU_LOCAL_TASK back to MENU_CALLBACK. The earlier change was causing some exceptions, and also caused a random "Configure block" tab to show up on block/overview page and link to nothing.

AttachmentSizeStatusTest resultOperations
606640-14-eojthebrave-block_router_paths.patch27.06 KBIdleFailed: Failed to apply patch.View details | Re-test

#15

eojthebrave - October 16, 2009 - 21:27
Status:needs work» needs review

#16

sun - October 16, 2009 - 21:51
Status:needs review» reviewed & tested by the community

Nice job!

#17

sun - October 16, 2009 - 21:55
Status:reviewed & tested by the community» needs work

oh wait.

#18

sun - October 16, 2009 - 21:59

+++ modules/block/block.admin.inc
@@ -88,12 +88,12 @@ function block_admin_display_form($form, &$form_state, $blocks, $theme) {
-        'admin/structure/block/delete/' . $block['delta']),
+        'admin/structure/block/manage/' . $block['delta'] . '/delete'),

Here, we miss a $block['module'], it seems.

Ah, no, we're missing a /block/ before the delta, but well, since $block['module'] == 'block', we can also keep it consistent and use the variable. :)

I'm on crack. Are you, too?

#19

eojthebrave - October 16, 2009 - 22:59
Status:needs work» needs review

Fixed. With tests so it won't happen again.

AttachmentSizeStatusTest resultOperations
606640-19-eojthebrave-block_router_paths.patch27.6 KBIdleFailed: Failed to apply patch.View details | Re-test

#20

sun - October 16, 2009 - 23:28
Status:needs review» reviewed & tested by the community

Awesome! Thanks so much, eojthebrave!

#21

webchick - October 16, 2009 - 23:49
Status:reviewed & tested by the community» fixed

Awesome!

Committed to HEAD!

#22

David_Rothstein - October 23, 2009 - 04:50
Status:fixed» active

See @catch's analysis at http://drupal.org/node/607244#comment-2179262 -- the way the block_load() function is being used here seems to be not so good for performance.

We may need to go back to something like the earlier simpler approach, which did not involve using a menu loader function (but rather unnamed placeholders)?

#23

catch - October 23, 2009 - 05:50

Subscribing. The issue here is that the menu system calls all loader functions when checking access callbacks - just in case they're needed, which they're not here - so moving to anonymous placeholders ought to fix it. We can also fix it in a roundabout way by using fieldable blocks, but that's a much more complicated patch which doesn't really have anything to do with this issue.

#24

sun - November 5, 2009 - 17:32
Status:active» needs review

Two things:

1) Revert menu arguments for block configuration paths to /%/% without autoloader for $block to increase performance.

2) Introduce a missing MENU_CONTEXT_NONE constant to allow a custom module/theme to expose the "Delete" link for blocks as well.

AttachmentSizeStatusTest resultOperations
drupal.block-menu.24.patch5.54 KBIdleFailed: Invalid PHP syntax in modules/block/block.module.View details | Re-test

#25

catch - November 5, 2009 - 17:41
Status:needs review» reviewed & tested by the community

Great patch.

#26

catch - November 5, 2009 - 18:00
Title:Use proper menu router paths for the block module» (Don't) Use proper menu router paths for the block module

#27

sun - November 5, 2009 - 18:57
Title:(Don't) Use proper menu router paths for the block module» Use proper menu router paths for the block module (but no argument loader functions)

Nope, it's still using proper menu router paths, but no longer argument loaders.

#28

System Message - November 7, 2009 - 23:55
Status:reviewed & tested by the community» needs work

The last submitted patch failed testing.

#29

catch - November 10, 2009 - 13:18
Status:needs work» needs review

Can't reproduce the syntax error locally, resubmitting.

AttachmentSizeStatusTest resultOperations
block.patch5.54 KBIdlePassed: 14723 passes, 0 fails, 0 exceptionsView details | Re-test

#30

sun - November 10, 2009 - 18:26

bot?

AttachmentSizeStatusTest resultOperations
drupal.block-menu.30.patch5.54 KBIdlePassed: 14686 passes, 0 fails, 0 exceptionsView details | Re-test

#31

catch - November 11, 2009 - 03:12
Category:task» bug report
Status:needs review» reviewed & tested by the community

#32

Dries - November 11, 2009 - 08:28
Status:reviewed & tested by the community» fixed

Looks good. Committed to CVS HEAD. Thanks.

#33

System Message - November 25, 2009 - 08:30
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.