Posted by h_razack on March 8, 2007 at 10:02pm
Hello everyone,
When we use hook_menu to create a menu item, and if we use NORMAL_MENU_ITEM, it adds it to the "navigation" menu.
1) Is it possible add it to another menu?
2) How can we actually create another menu programmatically?
Many thanks,
Hubert.
Comments
category
category.module is the only place i know of where this sort of thing being done.
Via Modules
Good place to start:
http://api.drupal.org/api/5/function/hook_menu
http://api.drupal.org/api/5/group/menu
Sorry about that
I answered too quickly. From my understanding hook_menu can only return menu items to the "Navigation" menu. An admin has to manually move it to another menu. Please correct me if I'm wrong, because I would love to have this functionality as well.
No idea on creating a brand new menu programmatically.
Well, that's what I thought,
Well, that's what I thought, it doesn't seem to be feasable right now.
It would be a great addition, though.
I had a look at the category module a while ago, when I worked on my first Drupal site, but although it is a great module I prefer to use as much as the core functionality as I can (due to upgrade and maintenance issues)
It is possible with menu_save_item()
Here's a function I used to create a menu from on terms found in a vocabulary.
<?phpfunction tax_to_menu($vid = 2, $menu_name = 'My Menu') {
$tree = taxonomy_get_tree($vid);
$item = array(
'pid' => 0,
'type' => 115,
'title' => $menu_name,
);
menu_save_item($item);
$pid = $item['mid'];
foreach($tree as $term) {
unset($item);
$item['pid'] = $pid;
$item['path'] = 'taxonomy/term/'. $term->tid;
$item['title'] = $term->name ;
$item['description'] = $term->description ;
$item['weight'] = $term->weight ;
$item['type'] = 118 ;
menu_save_item($item);
}
}
?>
You may need to clear your cache after running this function.
- China Business News & Observer -
function for changing node/{nr} to taxonomy/term/{nr}
Hi,
I see this function which creates menu items from taxonomy terms.
I have worked with the category module and I am not ok with this module, so I changed strategies to go back to taxonomy module. I stated the reasons why here: http://drupal.org/node/147279
Can you tell me how I may be can use your function to change the node/{nr} type 118 menu items (the old category module items) to taxonomy/term/{nr} items?
It would be great if this is possible!
Thanks in advance,
greetings,
Martijn
www.best-information.eu
menu_save_item deprecated in 6.x
This is something I did to create an empty menu:
function create_menu($menu_name, $menu_title, $description) {
$return_mlid = 0;
menu_rebuild();
// insert into the menu_custom database
if(!db_result(db_query("SELECT * FROM {menu_custom} WHERE menu_name = '%s'", $menu_name))) {
db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", $menu_name, $menu_title, $description);
} else {
db_query("UPDATE {menu_custom} SET title = '%s', description = '%s' WHERE menu_name = '%s'", $menu_title, $description, $menu_name);
}
// modified code from menu_enable
$base_link = db_fetch_array(db_query("SELECT mlid AS plid, menu_name from {menu_links} WHERE link_path = 'admin/build/menu' AND module = 'system'"));
$base_link['router_path'] = 'admin/build/menu-customize/%';
$base_link['module'] = 'menu';
$link = $base_link;
$link['mlid'] = 0;
$link['link_title'] = $menu_title;
$link['link_path'] = 'admin/build/menu-customize/'. $menu_name;
$link['module'] = 'alimag';
$link['customized'] = 1;
if (!db_result(db_query("SELECT mlid FROM {menu_links} WHERE link_path = '%s' AND plid = %d", $link['link_path'], $link['plid']))) {
$return_mlid = menu_link_save($link);
}
menu_cache_clear_all();
return $return_mlid;
}
---------------------
jray - Poulsbo, WA
To add a menu item to a
To add a menu item to a particular menu send the parent id value with the menu item as follows:
$items['menu_item']['pid'] = $pid;
eg:
$items['path'] = array(
'access' => $access,
'callback' => 'my_callback',
'description' => t('description'),
'path' => $path,
'title' => $name,
'weight' => 0,
'pid' => $pid
);
Passing Phase Web Development
{menu_custom}
Look for system_update_6021()
<?php$menus = array(
'navigation' => array(
'menu_name' => 'navigation',
'title' => 'Navigation',
'description' => 'The navigation menu is provided by Drupal and is the main interactive menu for any site. It is usually the only menu that contains personalized links for authenticated users, and is often not even visible to anonymous users.',
),
'primary-links' => array(
'menu_name' => 'primary-links',
'title' => 'Primary links',
'description' => 'Primary links are often used at the theme layer to show the major sections of a site. A typical representation for primary links would be tabs along the top.',
),
'secondary-links' => array(
'menu_name' => 'secondary-links',
'title' => 'Secondary links',
'description' => 'Secondary links are often used for pages like legal notices, contact details, and other secondary navigation items that play a lesser role than primary links.',
),
);
db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", $menus['primary-links']);
?>
Or look for menu_install()
<?phpdb_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", 'navigation', $t('Navigation'), $t('The navigation menu is provided by Drupal and is the main interactive menu for any site. It is usually the only menu that contains personalized links for authenticated users, and is often not even visible to anonymous users.'));
db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", 'primary-links', $t('Primary links'), $t('Primary links are often used at the theme layer to show the major sections of a site. A typical representation for primary links would be tabs along the top.'));
db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", 'secondary-links', $t('Secondary links'), $t('Secondary links are often used for pages like legal notices, contact details, and other secondary navigation items that play a lesser role than primary links'));
?>
Created new feature request: #449996: Function or hook for creating new menu_custom
Hi, I want to build a menu
Hi,
I want to build a menu using the combination of 3 vocabularies, say A, B and C
And want to build menu items like : "page-panel-name/A1/B1/C1, "page-panel-name"/A1/B1/C2 etc.....
(A1, B1, C1 and C2 are term names)
How can I deal with this using custom code please?
Thanks a lot in advance for your reply!
It sounds like you are after
It sounds like you are after something like this module.
While it doesn't use term names in the url it uses the term tids. If the module does what you want and you want term names then contact me and I'll see what I can do.
Passing Phase Web Development
Hi, Thanks for your
Hi, Thanks for your module!
The problem is with: "single level vocabularies". I tell you my use case:
I have a vocabulary: regional with
-countries
---regions
-------places
I have a vocabulary: camping sorts
-kidscamping
-nature-camping
etc..
and I have a vocabulary: specialities:
-swimmingpool
-restaurant
etc..
Next to this I have a page/panel on which I show differetn panes. The name of the panel is over
So what I would like is be able to build a menu with all these factors combined.
The url's in this menu should be:
over/holland/kidscamping/swimmingpoolover/holland/kidscamping/restaurant
etc..
Would this be possible with your module?
greetings,
Martijn
Only single level vocabularies
Unfortunately the module only does single level vocabularies. Coincidentally I have combined it with places in another module here called jobplus. This uses the addresses module to provide the location country and province/state so that you can search for categories within a country and a province/state. Here it is used for jobs but I could separate it out for generic use if you felt it is worthwhile. There's in implementation of the module here: http://www.dermpedia.org/jobs/7/21/36 .You can see there is a decent breadcrumb and informative blocks.
Passing Phase Web Development
Hi Kent, That would be great
Hi Kent,
That would be great to seperate out for generic use!
I do not know a correct module name, may be you are creative in this?
I would very much like to use the different taxonomies and be able to set a custom "word" before this combination.
Functionality:
1. Be able to set a word after the base_url (this way pages/panels/views can be triggered with arguments)
2. Be able to select 1 or 2 or 3 vocabularies
3. output urls using the word and output possible combinations in a order of choice and the hierarchy of the taxonomies shown automatically, like a sort of sitemap!
Thanks for your help in advance!
greetings, Martijn
Could someone please explain
Could someone please explain me what is the final verdict on this one?