[development] create a block with menu links
Lee Rowlands
contact at rowlandsgroup.com
Wed Sep 29 12:15:43 UTC 2010
Hi Lluis
It might be worth having a look at how devel module does it in function
devel_install.
It registers a new menu on install and adds menu items to the menu,
reusing the core menu and block modules and hence allowing the user to
modify the menu at a later date and also any other contrib modules that
interact with and extend these modules.
This is how the devel menu block is created.
Lee
On Wed, 2010-09-29 at 13:20 +0200, Lluís Forns wrote:
> One minor correction:
> $menu = array(
> 'path1' => 'title1',
> 'path2' => 'title2',
> );
> foreach($menu AS $key => $value) {
> $item=menu_get_item($key);
> if ($item['access'] !== TRUE) {
> unset($menu[$key]);
> }
> else {
> $menu[$key] = l($value, $key);
> }
> }
> $block['content'] = theme_item_list($menu);
> return $block;
>
>
>
> --
> *Les normes hi són perquè hi pensis abans de saltar-te-les
> *La vida és com una taronja, què esperes a exprimir-la?
> *Si creus que l'educació és cara, prova la ignorància.
> *La vida és com una moneda, la pots gastar en el que vulguis però
> només una vegada.
> *Abans d'imprimir aquest missatge, pensa en el medi ambient.
>
>
>
> 2010/9/29 Lluís Forns <enboig at gmail.com>:
> > After some research, I think the easiest way is to create a block in
> > my module and the in $delta=view put:
> > $menu = array(
> > 'path1' => 'title1',
> > 'path2' => 'title2',
> > );
> > foreach($menu AS $key => $value) {
> > if (!menu_get_item($key)) {
> > unset($menu[$key]);
> > }
> > else {
> > $menu[$key] = l($value, $key);
> > }
> > }
> > $block['content'] = theme_item_list($menu);
> > return $block;
> >
> >
> > It don't need and extra module and as it don't have any configuration,
> > it is easier to push changes from development site to production site.
> >
> > --
> > *Les normes hi són perquè hi pensis abans de saltar-te-les
> > *La vida és com una taronja, què esperes a exprimir-la?
> > *Si creus que l'educació és cara, prova la ignorància.
> > *La vida és com una moneda, la pots gastar en el que vulguis però
> > només una vegada.
> > *Abans d'imprimir aquest missatge, pensa en el medi ambient.
> >
> >
> >
> > 2010/9/29 Nikola Kotur <kotnick at gmail.com>:
> >> On Wed, 2010-09-29 at 09:58 +0200, Lluís Forns wrote:
> >>
> >> In my module I want to create a block with menu links. Which is the
> >> correct way to do it so permissions are checked?
> >>
> >> Why don't you use Menu Block module (http://drupal.org/project/menu_block )?
> >> Or, you could see in it how it should be properly done.
> >>
> >>
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20100929/f273d143/attachment.html
More information about the development
mailing list