initial commit of working dynamic menu items
parent
2dec350acd
commit
210a9c19f8
|
@ -3475,7 +3475,6 @@ function _menu_router_build($callbacks) {
|
|||
$menu = array();
|
||||
$masks = array();
|
||||
foreach ($callbacks as $path => $item) {
|
||||
$load_functions = array();
|
||||
$to_arg_functions = array();
|
||||
$fit = 0;
|
||||
$move = FALSE;
|
||||
|
@ -3493,20 +3492,10 @@ function _menu_router_build($callbacks) {
|
|||
if (preg_match('/^%(|' . DRUPAL_PHP_FUNCTION_PATTERN . ')$/', $part, $matches)) {
|
||||
if (empty($matches[1])) {
|
||||
$match = TRUE;
|
||||
$load_functions[$k] = NULL;
|
||||
}
|
||||
else {
|
||||
if (function_exists($matches[1] . '_to_arg')) {
|
||||
$to_arg_functions[$k] = $matches[1] . '_to_arg';
|
||||
$load_functions[$k] = NULL;
|
||||
$match = TRUE;
|
||||
}
|
||||
if (function_exists($matches[1] . '_load')) {
|
||||
$function = $matches[1] . '_load';
|
||||
// Create an array of arguments that will be passed to the _load
|
||||
// function when this menu path is checked, if 'load arguments'
|
||||
// exists.
|
||||
$load_functions[$k] = isset($item['load arguments']) ? array($function => $item['load arguments']) : $function;
|
||||
$match = TRUE;
|
||||
}
|
||||
}
|
||||
|
@ -3526,7 +3515,6 @@ function _menu_router_build($callbacks) {
|
|||
$fit = (1 << $number_parts) - 1;
|
||||
}
|
||||
$masks[$fit] = 1;
|
||||
$item['_load_functions'] = $load_functions;
|
||||
$item['to_arg_functions'] = empty($to_arg_functions) ? '' : serialize($to_arg_functions);
|
||||
$item += array(
|
||||
'title' => '',
|
||||
|
@ -3632,14 +3620,14 @@ function _menu_router_build($callbacks) {
|
|||
// Same for load arguments: if a loader doesn't have any explict
|
||||
// arguments, try to find arguments in the parent.
|
||||
if (!isset($item['load arguments'])) {
|
||||
foreach ($item['_load_functions'] as $k => $function) {
|
||||
foreach ($item['load functions'] as $k => $function) {
|
||||
// This loader doesn't have any explict arguments...
|
||||
if (!is_array($function)) {
|
||||
// ... check the parent for a loader at the same position
|
||||
// using the same function name and defining arguments...
|
||||
if (isset($parent['_load_functions'][$k]) && is_array($parent['_load_functions'][$k]) && key($parent['_load_functions'][$k]) === $function) {
|
||||
if (isset($parent['load functions'][$k]) && is_array($parent['load functions'][$k]) && key($parent['load functions'][$k]) === $function) {
|
||||
// ... and inherit the arguments on the child.
|
||||
$item['_load_functions'][$k] = $parent['_load_functions'][$k];
|
||||
$item['load functions'][$k] = $parent['load functions'][$k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3657,7 +3645,7 @@ function _menu_router_build($callbacks) {
|
|||
$item['access callback'] = intval($item['access callback']);
|
||||
}
|
||||
|
||||
$item['load_functions'] = empty($item['_load_functions']) ? '' : serialize($item['_load_functions']);
|
||||
$item['load_functions'] = empty($item['load functions']) ? '' : serialize($item['load functions']);
|
||||
$item += array(
|
||||
'access arguments' => array(),
|
||||
'access callback' => '',
|
||||
|
|
|
@ -50,6 +50,7 @@ class UrlMatcher extends SymfonyUrlMatcher {
|
|||
$routes->add(hash('sha256', $router_item['path']), $this->convertDrupalItem($router_item));
|
||||
|
||||
if ($ret = $this->matchCollection($pathinfo, $routes)) {
|
||||
//drupal_set_message('<pre>' . var_export('test', TRUE) . '</pre>');
|
||||
// Stash the router item in the attributes while we're transitioning.
|
||||
$ret['drupal_menu_item'] = $router_item;
|
||||
|
||||
|
@ -82,7 +83,17 @@ class UrlMatcher extends SymfonyUrlMatcher {
|
|||
// become more complicated because we'll need to get back candidates for a
|
||||
// path and them resolve them based on things like method and scheme which
|
||||
// we currently can't do.
|
||||
return menu_get_item($path);
|
||||
$item = menu_get_item($path);
|
||||
$path_elements = explode('/', $item['path']);
|
||||
$i = 0;
|
||||
foreach ($path_elements as $key => $element) {
|
||||
if ($element == '%') {
|
||||
$path_elements[$key] = "{arg$i}";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$item['path'] = implode('/', $path_elements);
|
||||
return $item;
|
||||
}
|
||||
|
||||
protected function convertDrupalItem($router_item) {
|
||||
|
|
|
@ -2072,32 +2072,41 @@ function node_menu() {
|
|||
'title' => $type->name,
|
||||
'title callback' => 'check_plain',
|
||||
'page callback' => 'node_add',
|
||||
'page arguments' => array($type->type),
|
||||
'page arguments' => array('type' => $type->type),
|
||||
'access callback' => 'node_access',
|
||||
'access arguments' => array('create', $type->type),
|
||||
'description' => $type->description,
|
||||
'file' => 'node.pages.inc',
|
||||
);
|
||||
}
|
||||
$items['node/%node'] = array(
|
||||
$items['node/%'] = array(
|
||||
'load functions' => array(
|
||||
1 => 'node_load',
|
||||
),
|
||||
'title callback' => 'node_page_title',
|
||||
'title arguments' => array(1),
|
||||
// The page callback also invokes drupal_set_title() in case
|
||||
// the menu router's title is overridden by a menu link.
|
||||
'page callback' => 'node_page_view',
|
||||
'page arguments' => array(1),
|
||||
'page arguments' => array('node' => 1),
|
||||
'access callback' => 'node_access',
|
||||
'access arguments' => array('view', 1),
|
||||
);
|
||||
$items['node/%node/view'] = array(
|
||||
$items['node/%/view'] = array(
|
||||
'load functions' => array(
|
||||
1 => 'node_load',
|
||||
),
|
||||
'title' => 'View',
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
'weight' => -10,
|
||||
);
|
||||
$items['node/%node/edit'] = array(
|
||||
$items['node/%/edit'] = array(
|
||||
'load functions' => array(
|
||||
1 => 'node_load',
|
||||
),
|
||||
'title' => 'Edit',
|
||||
'page callback' => 'node_page_edit',
|
||||
'page arguments' => array(1),
|
||||
'page arguments' => array('node' => 1),
|
||||
'access callback' => 'node_access',
|
||||
'access arguments' => array('update', 1),
|
||||
'weight' => 0,
|
||||
|
@ -2105,10 +2114,13 @@ function node_menu() {
|
|||
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
|
||||
'file' => 'node.pages.inc',
|
||||
);
|
||||
$items['node/%node/delete'] = array(
|
||||
$items['node/%/delete'] = array(
|
||||
'load functions' => array(
|
||||
1 => 'node_load',
|
||||
),
|
||||
'title' => 'Delete',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('node_delete_confirm', 1),
|
||||
'page arguments' => array('form_id' => 'node_delete_confirm', 1),
|
||||
'access callback' => 'node_access',
|
||||
'access arguments' => array('delete', 1),
|
||||
'weight' => 1,
|
||||
|
|
|
@ -796,7 +796,7 @@ function system_menu() {
|
|||
'title' => 'Performance',
|
||||
'description' => 'Enable or disable page caching for anonymous users and set CSS and JS bandwidth optimization options.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('system_performance_settings'),
|
||||
'page arguments' => array('form_id' => 'system_performance_settings'),
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'file' => 'system.admin.inc',
|
||||
'weight' => -20,
|
||||
|
|
Loading…
Reference in New Issue