I need to show a menu item only in certain moments. Imagine that I've a form with some options. If 'A' is selected, I need to enable a menu item that has a form for adding information about 'A'.
I have done a module that has a hook_menu like this:
> function secciones_menu() {
>
>
> $items = array();
>
> $items['secciones'] = array(
> 'title' => t('Crear Sección'),
> 'description' => t('Crear Secciones'),
> 'page callback' => 'drupal_get_form',
> 'page arguments' => array('secciones_wizard'),
> 'access callback' = TRUE,
> 'type' => MENU_NORMAL_ITEM,
> 'menu_name' => 'main-menu', 'customized' => 1, // Must be 1 in order to not dispaly the link in any language
> 'language' => 'es', // language is required in order to make the item translatable );
return $items; }
And then have my form for 'A'. So how I can enable or disable the menu item, depending a variable value?
Thank you !
EDIT 1:
What I've done is change the access callback and the menu type:
function agenda_menu() {
$items = array();
$items['agenda'] = array(
'title' => t('4. Crear agenda'),
'description' => t('Crear agenda'),
'parent'=>array('Configurar Revista'),
'page callback' => 'drupal_get_form',
'page arguments' => array('agenda_wizard'),
'access callback' => 'agenda_access_callback',
'type' => MENU_DEFAULT_LOCAL_TASK,
'menu_name' => 'main-menu',
'customized' => 1, // Must be 1 in order to not dispaly the link in any language
'language' => 'es', // language is required in order to make the item translatable
);
return $items;
}
And then I've done the next code:
function agenda_access_callback(){
//db query
//insert that query in $options array
foreach ($result as $row) {
$options[$row->id_seccion] = $row->id_seccion;
}
if(isset($options)){ //if the array is not empty
return TRUE; //the menu item is visible
}
else{
return FALSE; //otherwise, is not visible
}
}
Ok, this is what I have done, but it doesn't work. Any idea? Thank you.