MENU_LOCAL_TASK for just some node types
I want to make avaliable a local menu for just some node types, how can I achieve this? thanks. -- *La felicitat ha de ser compatible, compartible i cooperativa. *Envellim quan els records superen les esperances. *Als llocs desconeguts només s'hi arriba per camins desconeguts. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
Quoting Lluís <enboig@gmail.com>:
I want to make avaliable a local menu for just some node types, how can I achieve this?
I think this is the wrong list; see http://drupal.org/support for more appropriate help. Earnie -- http://for-my-kids.com/ -- http://give-me-an-offer.com/
Lluís wrote:
I want to make avaliable a local menu for just some node types, how can I achieve this?
I think this is development related enough so here goes: Create a conditional menu item inside of if(!$may_cache) that tests the node->type against you desired nodes. This will prevent the LMT from always showing up. If you want to get fancy let the user select the allowable node types via a settings page and pull the data via variable_get(). This information applies to Drupal-5 but may be modified to apply to drupal 6. good luck. -- Michael Favia michael@favias.org tel. 512.585.5650 http://www.favias.org
I believe you mean *outside* of $may_cache. -----Original Message----- From: Michael Favia <michael@favias.org> Date: Thu, 05 Jun 2008 09:03:26 To:development@drupal.org Subject: Re: [development] MENU_LOCAL_TASK for just some node types Lluís wrote:
I want to make avaliable a local menu for just some node types, how can I achieve this?
I think this is development related enough so here goes: Create a conditional menu item inside of if(!$may_cache) that tests the node->type against you desired nodes. This will prevent the LMT from always showing up. If you want to get fancy let the user select the allowable node types via a settings page and pull the data via variable_get(). This information applies to Drupal-5 but may be modified to apply to drupal 6. good luck. -- Michael Favia michael@favias.org tel. 512.585.5650 http://www.favias.org
My problem is there is no $node object to check $node->type. My menu definition is: function comptacau_project_menu() { $items=array(); $items[] = array('path' => 'node/'. arg(1) .'/pressupost_form', 'title' => t('Pressupost'), 'callback' => 'devel_load_object', 'callback arguments' => array('node', arg(1)), 'access' => user_access('access devel information'), 'type' => MENU_LOCAL_TASK, ); return $items; } When I get it all working; I will check if this goes inside cache or outside On Thu, Jun 5, 2008 at 4:17 PM, David Strauss <david@fourkitchens.com> wrote:
I believe you mean *outside* of $may_cache.
-----Original Message----- From: Michael Favia <michael@favias.org>
Date: Thu, 05 Jun 2008 09:03:26 To:development@drupal.org Subject: Re: [development] MENU_LOCAL_TASK for just some node types
Lluís wrote:
I want to make avaliable a local menu for just some node types, how can I achieve this?
I think this is development related enough so here goes:
Create a conditional menu item inside of if(!$may_cache) that tests the node->type against you desired nodes. This will prevent the LMT from always showing up. If you want to get fancy let the user select the allowable node types via a settings page and pull the data via variable_get(). This information applies to Drupal-5 but may be modified to apply to drupal 6. good luck.
-- Michael Favia michael@favias.org tel. 512.585.5650 http://www.favias.org
-- *La felicitat ha de ser compatible, compartible i cooperativa. *Envellim quan els records superen les esperances. *Als llocs desconeguts només s'hi arriba per camins desconeguts. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
Lluís wrote:
My problem is there is no $node object to check $node->type. My menu definition is:
My mistake. You are correct. To my knowledge you will either have to load the node or if you have pathauto working and uniquely prefix the node type you can test the path for the presence of the token for that type. (it is pretty hackish but ive used it before to avoid the excessive database hits). -- Michael Favia michael@favias.org tel. 512.585.5650 http://www.favias.org
Hi, You can use node_load() to get node type attribute. function comptacau_project_menu($may_cache) { $items=array(); if (arg(0) == 'node' && is_numeric(arg(1))) { $node = node_load(arg(1)); // DEBUG: Example with 'page' but can be anything else ... if ($node->type == 'page') { $items[] = array( 'path' => 'node/'. arg(1) . '/pressupost_form', 'title' => t('Pressupost'), 'callback' => 'devel_load_object', 'callback arguments' => array($node), 'access' => user_access('access devel information'), 'type' => MENU_LOCAL_TASK ); } } return $items; } G. Saint-Genest -- Gwenael Saint-Genest MAKINA CORPUS - www.makina-corpus.com 44 boulevard des Pas Enchantés FR-44230 Saint Sébastien sur Loire Tel : +33 (0) 2 40 94 96 08
It works prefectly, thanks a lot. On Thu, Jun 5, 2008 at 5:02 PM, Saint-Genest Gwenael <gwenael.saint-genest@makina-corpus.com> wrote:
Hi,
You can use node_load() to get node type attribute.
function comptacau_project_menu($may_cache) { $items=array(); if (arg(0) == 'node' && is_numeric(arg(1))) { $node = node_load(arg(1)); // DEBUG: Example with 'page' but can be anything else ... if ($node->type == 'page') { $items[] = array( 'path' => 'node/'. arg(1) . '/pressupost_form', 'title' => t('Pressupost'), 'callback' => 'devel_load_object', 'callback arguments' => array($node), 'access' => user_access('access devel information'), 'type' => MENU_LOCAL_TASK ); } } return $items; }
G. Saint-Genest
-- Gwenael Saint-Genest MAKINA CORPUS - www.makina-corpus.com 44 boulevard des Pas Enchantés FR-44230 Saint Sébastien sur Loire Tel : +33 (0) 2 40 94 96 08
-- *La felicitat ha de ser compatible, compartible i cooperativa. *Envellim quan els records superen les esperances. *Als llocs desconeguts només s'hi arriba per camins desconeguts. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
not prefectly; I have observed an odd behaviour with my function: it just works the first time I change the path ("pressupostos" by something else); as soon as I clear the cache (using devel module) the tab disappear. function comptacau_project_menu() { global $node; $items=array(); if ($may_cache) { $items[] = array('path' => 'comptacau/projects_autocomplete', 'title' => t('project_autocomplete'), 'callback' => 'projects_autocomplete', 'access' => comptacau_access('search_project'), 'type' => MENU_CALLBACK); } else { //no cache if (arg(1)>0) { //just load the node when there is a node $node = node_load(arg(1)); } $items[] = array('path' => 'node/'. arg(1) .'/pressupostos', //if I change this line, the tab appear 'title' => t('Pressupost'), 'callback' => 'drupal_get_form', 'callback arguments' => array('comtpacau_project_pressupost_form',arg(1)), 'access' => ($node->type=='comptacau_project'), 'type' => MENU_LOCAL_TASK); } return $items; } What am I missing? thanks a lot On Thu, Jun 5, 2008 at 5:30 PM, Lluís <enboig@gmail.com> wrote:
It works prefectly, thanks a lot.
On Thu, Jun 5, 2008 at 5:02 PM, Saint-Genest Gwenael <gwenael.saint-genest@makina-corpus.com> wrote:
Hi,
You can use node_load() to get node type attribute.
function comptacau_project_menu($may_cache) { $items=array(); if (arg(0) == 'node' && is_numeric(arg(1))) { $node = node_load(arg(1)); // DEBUG: Example with 'page' but can be anything else ... if ($node->type == 'page') { $items[] = array( 'path' => 'node/'. arg(1) . '/pressupost_form', 'title' => t('Pressupost'), 'callback' => 'devel_load_object', 'callback arguments' => array($node), 'access' => user_access('access devel information'), 'type' => MENU_LOCAL_TASK ); } } return $items; }
G. Saint-Genest
-- Gwenael Saint-Genest MAKINA CORPUS - www.makina-corpus.com 44 boulevard des Pas Enchantés FR-44230 Saint Sébastien sur Loire Tel : +33 (0) 2 40 94 96 08
-- *La felicitat ha de ser compatible, compartible i cooperativa. *Envellim quan els records superen les esperances. *Als llocs desconeguts només s'hi arriba per camins desconeguts. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
-- *La felicitat ha de ser compatible, compartible i cooperativa. *Envellim quan els records superen les esperances. *Als llocs desconeguts només s'hi arriba per camins desconeguts. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
After some checking the problems just exists if I clean cache while looking a node of this type; if I clear cache from de front page everything works ok. It works so I don't need to change it, but I would like to understand why does it happen. On Fri, Jun 6, 2008 at 10:26 AM, Lluís <enboig@gmail.com> wrote:
not prefectly; I have observed an odd behaviour with my function: it just works the first time I change the path ("pressupostos" by something else); as soon as I clear the cache (using devel module) the tab disappear.
function comptacau_project_menu() { global $node; $items=array();
if ($may_cache) { $items[] = array('path' => 'comptacau/projects_autocomplete', 'title' => t('project_autocomplete'), 'callback' => 'projects_autocomplete', 'access' => comptacau_access('search_project'), 'type' => MENU_CALLBACK); } else { //no cache if (arg(1)>0) { //just load the node when there is a node $node = node_load(arg(1)); } $items[] = array('path' => 'node/'. arg(1) .'/pressupostos', //if I change this line, the tab appear 'title' => t('Pressupost'), 'callback' => 'drupal_get_form', 'callback arguments' => array('comtpacau_project_pressupost_form',arg(1)), 'access' => ($node->type=='comptacau_project'), 'type' => MENU_LOCAL_TASK); } return $items; }
What am I missing?
thanks a lot
On Thu, Jun 5, 2008 at 5:30 PM, Lluís <enboig@gmail.com> wrote:
It works prefectly, thanks a lot.
On Thu, Jun 5, 2008 at 5:02 PM, Saint-Genest Gwenael <gwenael.saint-genest@makina-corpus.com> wrote:
Hi,
You can use node_load() to get node type attribute.
function comptacau_project_menu($may_cache) { $items=array(); if (arg(0) == 'node' && is_numeric(arg(1))) { $node = node_load(arg(1)); // DEBUG: Example with 'page' but can be anything else ... if ($node->type == 'page') { $items[] = array( 'path' => 'node/'. arg(1) . '/pressupost_form', 'title' => t('Pressupost'), 'callback' => 'devel_load_object', 'callback arguments' => array($node), 'access' => user_access('access devel information'), 'type' => MENU_LOCAL_TASK ); } } return $items; }
G. Saint-Genest
-- Gwenael Saint-Genest MAKINA CORPUS - www.makina-corpus.com 44 boulevard des Pas Enchantés FR-44230 Saint Sébastien sur Loire Tel : +33 (0) 2 40 94 96 08
-- *La felicitat ha de ser compatible, compartible i cooperativa. *Envellim quan els records superen les esperances. *Als llocs desconeguts només s'hi arriba per camins desconeguts. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
-- *La felicitat ha de ser compatible, compartible i cooperativa. *Envellim quan els records superen les esperances. *Als llocs desconeguts només s'hi arriba per camins desconeguts. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
-- *La felicitat ha de ser compatible, compartible i cooperativa. *Envellim quan els records superen les esperances. *Als llocs desconeguts només s'hi arriba per camins desconeguts. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
Lluís wrote:
not prefectly; I have observed an odd behaviour with my function: it just works the first time I change the path ("pressupostos" by something else); as soon as I clear the cache (using devel module) the tab disappear.
function comptacau_project_menu() { (... snip ...)
What am I missing?
thanks a lot
I think you can have best results with a "$may_cache" parameter to the function ;) Gwen -- Gwenael Saint-Genest MAKINA CORPUS - www.makina-corpus.com 44 boulevard des Pas Enchantés FR-44230 Saint Sébastien sur Loire Tel : +33 (0) 2 40 94 96 08
David Strauss wrote:
I believe you mean *outside* of $may_cache. -----Original Message----- From: Michael Favia <michael@favias.org> Create a conditional menu item inside of if(!$may_cache) that tests the
Either inside of if (!$may_cache) {as i wrote above} or outside of if ($may_cache) works perfectly fine of course. -- Michael Favia michael@favias.org tel. 512.585.5650 http://www.favias.org
Apologies. I somehow missed the "!" when reading this on my BlackBerry. That's what I get for emailing the developer list when I'm 10 minutes out of bed. ----- "David Strauss" <david@fourkitchens.com> wrote:
I believe you mean *outside* of $may_cache.
-----Original Message----- From: Michael Favia <michael@favias.org>
Date: Thu, 05 Jun 2008 09:03:26 To:development@drupal.org Subject: Re: [development] MENU_LOCAL_TASK for just some node types
Lluís wrote:
I want to make avaliable a local menu for just some node types, how can I achieve this?
I think this is development related enough so here goes:
Create a conditional menu item inside of if(!$may_cache) that tests the node->type against you desired nodes. This will prevent the LMT from always showing up. If you want to get fancy let the user select the allowable node types via a settings page and pull the data via variable_get(). This information applies to Drupal-5 but may be modified to apply to drupal 6. good luck.
-- Michael Favia michael@favias.org tel. 512.585.5650 http://www.favias.org
participants (6)
-
David Strauss -
David Timothy Strauss -
Earnie Boyd -
Lluís -
Michael Favia -
Saint-Genest Gwenael