If I create the following menu item in hook_menu, then calling that path causes the fatal error PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0 in D7 (A page not found in D6).


  $items['test/%node/%test'] = array(
    'title' => 'Test',
    'load arguments' => array('%map', '%index'),
    'description' => "Test some code here",
    'page callback' => 'test_call',
    'page arguments' => array(1, 2),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

This happens because node_load does not check the $revision argument that gets passed in for validity as a vid. i.e. all vid's should be numeric. I'm not sure how this might affect the node_load_multiple, but for node_load the following patches should correct the issue. At least they do for me.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch failed testing.

cdale’s picture

Status: Needs work » Needs review
FileSize
1.12 KB

Reroll ro remove notices.

cdale’s picture

Priority: Normal » Critical

I feel this is probably critical. Feel free to correct me.

Status: Needs review » Needs work

The last submitted patch failed testing.

cdale’s picture

Status: Needs work » Needs review
cdale’s picture

Title: Fatal Error when %node used in menu with 'load arguments' » Can't use 'load arguments' with %node. Fatal error.
Component: node system » menu system

Does anyone else have any designs, ideas or other ways to achieve using load arguments with %node? Is this a flaw with the menu system that this can not be done? Or is the fault with node_load?

Damien Tournoud’s picture

Status: Needs review » Closed (won't fix)
  $items['test/%node/%test'] = array(
    'title' => 'Test',
    'load arguments' => array('%map', '%index'),
    'description' => "Test some code here",
    'page callback' => 'test_call',
    'page arguments' => array(1, 2),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

This should be:

  $items['test/%node/%'] = array(
    'title' => 'Test',
    'description' => "Test some code here",
    'page callback' => 'test_call',
    'page arguments' => array(1, 2),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
cdale’s picture

Title: Can't use 'load arguments' with %node. Fatal error. » Different load arguments for multiple % wildcards in path.
Category: bug » feature
Priority: Critical » Normal
Status: Closed (won't fix) » Needs review
FileSize
1.23 KB

Is there some documentation for this somewhere that I've missed? Does this only apply when using 'load arguments'? I guess this would not be a problem if the 'load arguments' key was not there.

I think it could be useful to be able to do this, as such I've made a patch.

It allows load arguments to be defined as below:

  $items['test/%wild/path/%test'] = array(
    'title' => 'Test',
    'load arguments 1' => array('1', 'TEST'),
    'load arguments 3' => array('%map', '%index'),
    'description' => "Test some code here",
    'page callback' => 'test_call',
    'page arguments' => array(1, 2),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

This allows for multiple _load functions to be used, with different load arguments for each if desired. It will also work as is currently i.e the code below will still work:

  $items['test/%test/path/%'] = array(
    'title' => 'Test',
    'load arguments' => array('%map', '%index'),
    'description' => "Test some code here",
    'page callback' => 'test_call',
    'page arguments' => array(1, 2),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

Does this seem like a reasonable solution? What are peoples thoughts for allowing this? Probably not a huge demand for it, but it could be useful, and it is a minimal change to allow it, and it breaks no existing functionality that I can see.

cburschka’s picture

Status: Needs review » Needs work
    'load arguments 1' => array('1', 'TEST'),
    'load arguments 3' => array('%map', '%index'),

I'm not well-versed enough in the menu system to know whether this feature is needed, but this property should definitely be an array rather than numbered keys:

  $items['test/%wild/path/%test'] = array(
    'title' => 'Test',
    'load arguments' => array(
      1 => array('1', 'TEST'),
      3 => array('%map', '%index'),
    ),
    'description' => "Test some code here",
    'page callback' => 'test_call',
    'page arguments' => array(1, 2),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

This also allows for a convenient is_array() check (making it backward compatible). What you lose is the option of defining the same load arguments for several placeholders, but not all. But that seems like a rare edge case where you may as well define the load arguments for each placeholder separately.

andypost’s picture

subscribe

webchick’s picture

Version: 7.x-dev » 8.x-dev
Cyberwolf’s picture

Subscribing.

casey’s picture

subscribe

andypost’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue summary: View changes

patch outdated, and looks like 8.1.x as feature

Berdir’s picture

Version: 8.1.x-dev » 8.0.x-dev
Status: Needs work » Closed (cannot reproduce)

This doesn't make sense anymore, the routing is completely different and and has no issues with multiple arguments that are upcasted.