In my module I want to create a block with menu links. Which is the correct way to do it so permissions are checked? I thought of creating a block and add l() funcionits, but l() don't check permission, and using if(users_accesss()) don't look smart. Thanks -- *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.
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.
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@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.
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@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@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.
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@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@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.
Perhaps I am confused as to why this is a confusing topic. Standard menu definitions can be put into any menu (which is already effectively a block). The menu system supports a "menu_name" parameter. $items['mystats'] = array( 'title' => 'My Statistics', 'description' => 'See my post statistics', 'page callback' => 'mymodule_mystats', 'access arguments' => array('view analyst statistics'), 'type' => MENU_NORMAL_ITEM, 'menu_name' => 'menu-analyst', ); So, just do this in your standard menu building code. In this case, you then enable the "menu-analyst" block. Nancy Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr. ________________________________ From: Lluís Forns In my module I want to create a block with menu links. Which is the correct way to do it so permissions are checked? I thought of creating a block and add l() funcionits, but l() don't check permission, and using if(users_accesss()) don't look smart.
To Lee Rowlands; using just "hook_install()" is not an option; when I make changes to my devel site, it is easier to just upload files and clear cache than go through admin menus and repeat the changes. To Nan Wich: I didn't know about this approach. I added my menu to database using hook_update_n() and after changing my menu structure it works perfect now. -- *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 nan wich <nan_wich@bellsouth.net>:
Perhaps I am confused as to why this is a confusing topic. Standard menu definitions can be put into any menu (which is already effectively a block). The menu system supports a "menu_name" parameter. $items['mystats'] = array( 'title' => 'My Statistics', 'description' => 'See my post statistics', 'page callback' => 'mymodule_mystats', 'access arguments' => array('view analyst statistics'), 'type' => MENU_NORMAL_ITEM, 'menu_name' => 'menu-analyst', ); So, just do this in your standard menu building code. In this case, you then enable the "menu-analyst" block.
Nancy
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
________________________________ From: Lluís Forns In my module I want to create a block with menu links. Which is the correct way to do it so permissions are checked? I thought of creating a block and add l() funcionits, but l() don't check permission, and using if(users_accesss()) don't look smart.
participants (4)
-
Lee Rowlands -
Lluís Forns -
nan wich -
Nikola Kotur