I asked this question earlier The 'drupal' way to implement delete button UI The answer worked perfectly. I would like to take it a step further and make sure my routing is done the best way for Drupal. (I'd hate to think there's some uber-powerful method out there I'm missing out on).
snippet from hook_menu():
$items['bluenose/rmlist/%'] = array(
'page callback' => 'bluenose_app_rmelement',
'page arguments' => array(1, 2),
'access arguments' => array ('access bluenose_app wishlists'),
'type' => MENU_LOCAL_TASK,
);
$items['bluenose/rmlistitem/%']=array(
'page callback' => 'bluenose_app_rmelement',
'page arguments' => array(1, 2),
'access arguments' => array ('access bluenose_app wishlists'),
'type' => MENU_LOCAL_TASK,
);
$items['bluenose/rmavailableprop/%']=array(
'page callback' => 'bluenose_app_rmelement',
'page arguments' => array(1, 2),
'access arguments' => array ('access bluenose_app wishlists'),
'type' => MENU_LOCAL_TASK,
);
The method those route to:
function bluenose_app_rmelement($type, $id)
{
switch($type)
{
case 'rmlist':
bluenose_app_remove_wishlist($id);
drupal_goto('bluenose/wishlists');
break;
case 'rmlistitem':
bluenose_app_remove_list_item($id);
drupal_goto('');
break;
case 'rmavailableproperty':
bluenose_app_remove_available_property($id);
drupal_goto('');
break;
default:
break;
}
}
Just to clarify the flow:
There are three hook_menu items that route $type
and $id
to a common rm* method.
This method switches among possible $type
params. When it hits the right one, it calls the appropriate remove method (which performs basic crud), then calls drupal_goto()
with a url that makes sense to the end-user.
How's that method chain look to you guys? Thanks a lot!
bluenose_app_rmelement()
instead of calling the correct callback inhook_menu()
?