[drupal-devel] menu system idea

Adrian Rossouw adrian at bryght.com
Sun Jun 19 12:00:54 UTC 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 19 Jun 2005, at 11:17 AM, Gerhard Killesreiter wrote:
>> On 19 Jun 2005, at 10:26, Robert Douglass wrote:
>>
>>> The nested arrays don't bother me. How much work would one have to
>>> do in this direction before we would be able to 1) measure
>>> performance and 2) rule out any "gottchas" that would make it less
>>> attractive than it initially seems?
First step is speaking to JonBob about this, as he has a much better  
understanding
re: the gotchas of the menu system than any of us.

He might have considered the same, but decided against it.

> I don't see how this could be improved using Adrian's arrays.
Oddly enough, i harbour no love for multi-dimensional arrays =)

I do however think this is one of the cases where they will actually  
provide
a more natural access method to the data they contain.

For instance, if you want to get all the child pages for node , you can
just cycle through $menu['node'], and print all the children that have
'item' elements.

Same with drawing the local tasks.

I just think that using a tree to store a .. you know.. tree, results
in clearer, and easier to debug code.


>> The current menu system has two important drawbacks:
>>    1. it is slow -- we had to add menu caching, but even with caching
>> it is slow.
>>
>
> If Adrian's scheme can improve performance, I'd be all for it. I'd  
> still
> the code is ugly, but ...
The data we are manipulating is much simpler, and doesn't need to
be 'built' into anything. The data that has been defined by the module
developer is the data used to traverse and render the menu system.


>>    2. it is complex -- it tends to be difficult to make simple  
>> changes.
>>
>
> One change I'd like to see is that permissions also apply to child  
> menu
> items. For example the user permission "access administration pages"
> applies to the path "admin", but not to any of the child menu items.

The following addition to the code i sent earlier does just that.

I would also like to be able to add additional properties to menu  
items, and
save it somewhere in the database.
For instance, I would like to be able to set a 'section' bit on a  
menu item,
and then have that cascade down.
That could be used to set all admin/ pages to use a different theme  
for instance.

   define('item', '__item');

   $menu[item] = array('title' => 'root page', 'callback' =>  
'root_page', 'access' => true);
   $menu['node'][item] = array('title' => 'listing', 'callback' =>  
'node_listing', 'access' => true);
   $menu['node']['add']['blog']['here'][item] = array('title' =>  
'blog entry', 'callback' => 'some_func' );
   $menu['node']['add'][item] = array('title' => 'create content',  
'callback' => 'node_page', 'access' => false);

   $path = explode('/', $_GET['q']);
   $q = $path;
   while (sizeof($q)) {
    $vars = array();
     $page = array();
     $access = $menu[item]['access'];
     $current = $menu;
     foreach ($q as $i) {
       if (array_key_exists($i, $current)) {
         $page[] = $i;
         $current = $current[$i];
         if (array_key_exists(item, $current)) {
           if (array_key_exists('access', $current[item])) {
             $access = $current[item]['access'] && $access;
           }
         }
       }
       else {
         break;
       }
     }
     if (array_key_exists(item, $current)) {
       $callback = $current[item]['callback'];
       $args = array_slice($path, (sizeof($page)) ? sizeof($page) : 1);
       break;
     }
     array_pop($q);
   }
   print_r(array('callback' => $callback, 'args' => $args, 'access'  
=> ($access) ? 'true' : 'false'));

- --
Adrian Rossouw
Drupal developer and Bryght Guy
http://drupal.org | http://bryght.com


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFCtV8LgegMqdGlkasRAjXTAJsG1a38qnmkQxcQ3oD6OflImVH2yQCeOrAL
U36y7nx2/wkP7kZeMisOmt8=
=JnSz
-----END PGP SIGNATURE-----



More information about the drupal-devel mailing list