[drupal-devel] menu system idea
Adrian Rossouw
adrian at bryght.com
Sat Jun 18 23:31:30 UTC 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
And here's an example of how you would get the right menu callback :
<?php
define('item', '__item');
$menu[item] = array('title' => 'root page', 'callback' =>
'root_page');
$menu['node'][item] = array('title' => 'listing', 'callback' =>
'node_listing');
$menu['node']['add']['blog']['here'][item] = array('title' =>
'blog entry', 'callback' => 'some_func' );
$menu['node']['add'][item] = array('title' => 'create content',
'callback' => 'node_page');
$path = explode('/', $_GET['q']);
$q = $path;
while (sizeof($q)) {
$vars = array();
$page = array();
$current = $menu;
foreach ($q as $i) {
if (array_key_exists($i, $current)) {
$page[] = $i;
$current = $current[$i];
}
else {
break;
}
}
if (array_key_exists(item, $current)) {
$callback = $current[item]['callback'];
$args = array_slice($path, sizeof($page));
break;
}
array_pop($q);
}
print_r(array('callback' => $callback, 'args' => $args));
?>
Another thing that's interesting about this code, is that we can set
up a root menu handler
ie
$menu[item] = array(/* stuff */);
Which might end up being a cleaner way of doing the variable_get
('site_frontpage') stuff.
On 19 Jun 2005, at 12:04 AM, Adrian Rossouw wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Instead of defining menu's as we do now (using 'path' => ) , why
> don't we skip the entire building a tree thing and just define the
> menu entries as trees to begin with?
>
> ie :
> $menu['node']['add']['blog'][ITEM] = array(title => t('blog
> entry'), access => user_access('edit own blog'));
> $menu['blog'][ITEM] = array(title => t('blogs'), callback =>
> 'blog_page', access => user_access('access content'), type =>
> MENU_SUGGESTED_ITEM);
>
> (ITEM would just be a define('ITEM', '__item') to avoid namespace
> conflicts.)
>
> This would mean we could 'build' the menu, just by :
>
> $_menu = array();
> foreach (module_implements('menu') as $module) {
> $_menu = array_merge_recursive($_menu, module_invoke($module,
> 'menu'));
> }
>
> Furthermore, we could solve the multiple menu tree requirement by
> defining menu items for the primary navigation such as :
> $menu[PRIMARY]['node']['add']['blog'] = array(title => t('new
> post!'), access => user_access('edit own blog'));
>
> It might also simplify the menu system to the point where mere
> mortals can understand it =)
>
>
> - --
> Adrian Rossouw
> Drupal developer and Bryght Guy
> http://drupal.org | http://bryght.com
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.4 (Darwin)
>
> iD8DBQFCtJp7gegMqdGlkasRAsY/AJwJARgxJz3zgNQnySSM54XqYi3bDgCgo7ml
> ewl/EPrMJRsafBJrqQdQxaA=
> =wlf3
> -----END PGP SIGNATURE-----
>
- --
Adrian Rossouw
Drupal developer and Bryght Guy
http://drupal.org | http://bryght.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
iD8DBQFCtK9rgegMqdGlkasRAp4+AKCjrOeURlhdKEdFwePqZDWCLjMI5QCfRErf
fehRWUg9pGhkS2/Au9cRi+s=
=Wt8F
-----END PGP SIGNATURE-----
More information about the drupal-devel
mailing list