Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Considering this code:
$items['admin/structure/block/manage/%block/%'] = array(
'title' => 'Configure block',
'page callback' => 'drupal_get_form',
'page arguments' => array('block_admin_configure', 4),
'load arguments' => array(5),
'access arguments' => array('administer blocks'),
'file' => 'block.admin.inc',
);
$items['admin/structure/block/manage/%block/%/configure'] = array(
'title' => 'Configure block',
'type' => MENU_DEFAULT_LOCAL_TASK,
'tab_type' => 'context',
);
$items['admin/structure/block/manage/%block/%/delete'] = array(
'title' => 'Delete block',
'page callback' => 'drupal_get_form',
'page arguments' => array('block_custom_block_delete', 4),
'load arguments' => array(5),
'access arguments' => array('administer blocks'),
'type' => MENU_CALLBACK,
'file' => 'block.admin.inc',
);
Expected behavior: When requesting the path admin/structure/block/manage/foo/bar, block_load() gets two arguments: 'foo' and 'bar'.
Actual behavior: When requesting the path admin/structure/block/manage/foo/bar, block_load() gets one argument: 'foo'.
Comment | File | Size | Author |
---|---|---|---|
#17 | drupal.menu-load-arguments-inherit.17.patch | 5.48 KB | sun |
#11 | menu-load-arguments-inheritance.patch | 3.63 KB | mr.baileys |
#7 | load_inherit.patch | 1.34 KB | chx |
#6 | load_inherit.patch | 0 bytes | chx |
Comments
Comment #1
chx CreditAttribution: chx commentedWhen requesting the path admin/structure/block/manage/foo/bar, block_load() gets two arguments: 'foo' and 'bar'.
That's curious. Why do you expect that? The "rest of the path as arguments" is only applicable for page. Or are you saying that
then bar_load on foo/b/c wont get b and c as arguments??
Comment #2
sunIn this case, block_load() requires two arguments: $module and $delta. These are expected to be passed to the menu argument loader, and hence, block_load() can't be invoked with %block only.
For the path
admin/structure/block/manage/%block/%
- which defines load arguments - the load function arguments are properly stored in the database.For the path
admin/structure/block/manage/%block/%/configure
- which does not define load arguments on its own - only %block is stored as argument in load_functions.Since
admin/structure/block/manage/%block/%/configure
is a MENU_DEFAULT_LOCAL_TASK, I expected thatwould take over the defined
load arguments
from the parent, because I equally don't need to specify any other arguments defined by the parent to make the MENU_DEFAULT_LOCAL_TASK work as it should:I expected this behavior, because I can't see how any path of
can work at all when the "parent path" defines
load arguments
to allow the menu argument loader%block
, i.e. block_load(), to load the right thing, as in:(yes, you ranted there's no concept of parents, but you didn't explain why, so I'm not sure how I can grok that.)
I would expect this behavior as long as an item does not define
load arguments
on its own:Comment #3
chx CreditAttribution: chx commentedSo the bug is this:
While most page callback +page arguments, file + file path, delivery callback and theme callback inherits, load argument was left out. However, access callback only inherits for default tasks. So we need to make a decision what and how to inherit with load arguments. Given that load arguments were a last minute ugly bolt on in D6 which noone bother to fix in D7 we have three ways to go:
Comment #4
chx CreditAttribution: chx commentedComment #5
sunWith the new usage of local tasks/contextual links, I'm pretty sure that I'll not be the only one who runs into this bug + has no clue at all why it's not working, so I recommend doing #3.
It took 3 experienced Drupal developers to find out that "load arguments" are not inherited at all (which sounds quite simple, but it's totally not what you expect).
Comment #6
chx CreditAttribution: chx commentedthis is 2. Not that horribly complicated now that i thought it though.
Comment #7
chx CreditAttribution: chx commentedThat was too simple.
Comment #8
sunThanks! This seems to pass the bot and looks correct. However, we also want 1) a bit more docs and 2) tests. Not sure whether I'll get to do that.
Comment #9
sunoopsie
Comment #10
chx CreditAttribution: chx commentedGiven the rate people are helping with criticals we will release in 2011.
Edit: I deliberately deleted the title so people are not running screaming.
Comment #11
mr.baileysSo if I understand correctly, all that is needed to move this forward are tests (verify that 'load arguments' is inherited when not explicitly specified) and documentation?
Here's a stab at adding tests for it...
Comment #15
sun.core CreditAttribution: sun.core commentedNot critical. Please read and understand Priority levels of Issues, thanks.
Comment #16
sunBroken tags.
Comment #17
sunReworked those tests. Also had to rework that foreach loop in menu_router_build(), as it did not properly work and led to bogus load functions data.
Lastly, during debugging I recognized that we're needlessly unserializing a lot of menu item load functions, and serialize()/unserialize() is very slow, so this patch additionally fixes that.
Comment #18
chx CreditAttribution: chx commentedThis is sheer awesome: bugfix, test and performance boost.
Comment #19
sunJust to be precise: adding Performance tag. unserialize() is known to be slow. And the current usage is just useless.
Comment #20
sunAlthough my local box is totally not suitable for doing benchmarks, I've mass-applied the following range of current performance patches and am getting a nice boost:
#910190: Entire schema cache needlessly loaded on all pages
#910156: Remove 'description' keys from schema cache
#606966: 'load arguments' of parent path are not inherited
#910124: Clean up menu_contextual_links()
Test page: admin/config/development/devel; Garland; enabled Navigation menu block containing 1 taxonomy term link and 1 node link.
Comment #21
sun#17: drupal.menu-load-arguments-inherit.17.patch queued for re-testing.
Comment #22
sun#17: drupal.menu-load-arguments-inherit.17.patch queued for re-testing.
Comment #23
sunComment #24
Dave ReidJust because someone is upset doesn't mean we have to mark something as won't fix. Someone else is more than welcome to pick up work on a ticket.
Comment #25
sunAlthough badly needed, this is D8 material according to the rules (I had to learn today). It may be backported at a later point in time (though that's unlikely).
Comment #26
chx CreditAttribution: chx commentedThis is a performance boost, no reason to postpone just yet. If it does not get into 7.0 that's fine, it's not a critical.
Comment #27
sunComment #28
sun#17: drupal.menu-load-arguments-inherit.17.patch queued for re-testing.
Comment #29
webchickCommitted to HEAD. Thanks!
Comment #30
das-peter CreditAttribution: das-peter commentedPossible issue related to this patch: #979958: load_functions detection for menu items broken by patch #606966