Skip to content

Instantly share code, notes, and snippets.

@msankhala
Created July 30, 2014 07:55
Show Gist options
  • Save msankhala/77d1f39b98f5b322ad62 to your computer and use it in GitHub Desktop.
Save msankhala/77d1f39b98f5b322ad62 to your computer and use it in GitHub Desktop.
The menu system in Drupal is known to most people as “that thing in the cache I have to constantly clear to find my links!” That is true. Also, it’s a vastly powerful framework for, not just managing your URLs, but adding context and power around the URLs themselves.
//Load functions
//The following menu item receives a single argument to the URL, an ID for some data -
<?php
$item['my-module/%my_module_data'] = array(
'title' => 'My path',
'page callback' => 'my_module_path',
'page arguments' => array(1),
);
?>
//When this URL is received, Drupal appends ‘_load’ to the argument’s name to call its load function -
<?php
function my_module_data_load($my_data) {
// lookup $my_data index
return $my_data_object;
}
?>
//Now, your page callback will receive the full, loaded object, rather than just the ID from the URL -
<?php
function my_module_path($my_data_object) {
// object available, passed through load
// load function my_modula_data_load
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment