Hello,

I am using Drupal 6.27. I am trying to develop a module with dynamic links. There are a lot of topics, blog posts etc. for this issue but I couldn't find a solution to my problem.

First of all, the code in consideration is as follows:

<?php
/**
* Implementation of hook_menu()
*/
function emulov_programs_menu() {
 
// Start creating non-admin panel links
 
$items['programs'] = array( // Access path, URI, of the item
   
'title' => 'Programs',
   
'description' => 'Shows academic program information for this department',
   
'page callback' => 'emulov_programs_page', // Call this function
   
'access callback' => 'user_access', // Let Drupal handle the access permissions using user_access()
   
'access arguments' => array('view programs'), // The permissions need to access this menu item
   
'file' => 'program.pages.inc', // Call the above function from this file
   
'type' => MENU_NORMAL_ITEM, // Drupal defaults to this item.  For details look for hook_menu() in api.drupal.org
   
'menu_name' => 'primary-links', // Add to Primary Links menu
 
);

/**
* Implementation of hook_menu_link_alter()
*/
function emulov_programs_menu_link_alter(&$item, $menu) {
  if (
$item['link_path'] == 'programs') {
   
$item['expanded'] = 1;
  }
}
}
?>

and program.pages.inc file:

<?php
/**
* Page callback function for "programs" menu path
*/
function emulov_programs_page() {
 
// Return the text in the "Programs page introduction" in the admin panel
 
return variable_get('emulov_programs_proghome', '');
}
?>

This function creates a menu item with a static path to mysite.com/programs. However, sometimes emulov_programs_proghome variable is empty and in that case, I want to make /programs link as "nolink".

How I can manage to do this operation?

Thanks,

Comments

What do you mean by "nolink",

What do you mean by "nolink", that the link is hidden?

Absolutely. The link will be

Absolutely. The link will be hidden, however the title will be shown and the menu item can be expanded.

I forgot to mention that I am using Special Menu Items to get this "nolink" functionality.

Hi Emulov, you could tackle

Hi Emulov,

you could tackle it in a number of ways. The approach would of course change depending upon the intended use case.

The menu item can be a variable, this allows any number of dynamic links if placed inside a foreach. $programs would of course need to be populated with the intended menu item(s).

<?php
function emulov_programs_menu() {
$items = array();
$items[$programs] = array(
);
return
$items;
?>

Hello hapax legomenon,I have

Hello hapax legomenon,

I have modified the code according to your instructions.

<?php
  $field_proghome
= variable_get('emulov_programs_proghome_link', 'programs');
 
$items[$field_proghome] = array(
   
'title' => 'Programs',
   
'description' => '',
   
'page callback' => 'emulov_programs_page',
   
'access callback' => 'user_access',
   
'access arguments' => array('view programs'),
   
'file' => 'program.pages.inc',
   
'type' => MENU_NORMAL_ITEM,
   
'menu_name' => 'primary-links',
  );
?>

I am controlling the "emulov_programs_proghome_link" from the admin panel, I am having no problems in that. However, when I set

emulov_programs_proghome_link = 'nolink'

or

emulov_programs_proghome_link = '<nolink>'

or

emulov_programs_proghome_link = '#'

, the menu dissapears and it doesn't work. It is also not possible to edit the path from the Menus admin menu.

I think the module is not calling or processing Special Menu Items functions somehow.