function restws_menu_alter in RESTful Web Services 7
Same name and namespace in other branches
- 7.2 restws.module \restws_menu_alter()
Implements hook_menu_alter().
File
- ./
restws.module, line 178 - RESTful web services module.
Code
function restws_menu_alter(&$items) {
foreach (restws_get_resource_info() as $resource => $info) {
// @todo document 'menu path'
$menu_path = isset($info['menu_path']) ? $info['menu_path'] . '/%' : $resource . '/%';
// Replace existing page callbacks with our own (e.g. node/%)
if (isset($items[$menu_path])) {
// Prepend the page callback and the resource to the page arguments.
// So we can re-use it on standard HTML page requests.
array_unshift($items[$menu_path]['page arguments'], $resource, $items[$menu_path]['page callback']);
$items[$menu_path]['page callback'] = 'restws_page_callback';
}
elseif (isset($items[$menu_path . $resource])) {
$menu_path = $menu_path . $resource;
array_unshift($items[$menu_path]['page arguments'], $resource, $items[$menu_path]['page callback']);
$items[$menu_path]['page callback'] = 'restws_page_callback';
}
else {
$items[$menu_path] = array(
'page callback' => 'restws_page_callback',
'page arguments' => array(
$resource,
'drupal_not_found',
),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
}
// Resource base path (e.g. /node or /user) for creating resources.
// @todo fix 'menu path'
if (!isset($info['menu_path'])) {
if (isset($items[$resource])) {
// Prepend the page callback and the resource to the page arguments.
if (!isset($items[$resource]['page arguments'])) {
$items[$resource]['page arguments'] = array();
}
array_unshift($items[$resource]['page arguments'], $resource, $items[$resource]['page callback']);
$items[$resource]['page callback'] = 'restws_page_callback';
}
else {
$items[$resource] = array(
'page callback' => 'restws_page_callback',
'page arguments' => array(
$resource,
'drupal_not_found',
),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
}
}
}
}