By seanr on
I'm trying to programmatically move and enable a menu link:
$contact = db_fetch_array(db_query("SELECT 'mlid', 'link_path', 'link_title' FROM {menu_links} WHERE link_path = 'contact'"));
$contact['weight'] = 50;
$contact['menu_name'] = 'primary-links';
$contact['hidden'] = 0;
menu_link_save($contact);
My code doesn't seem to do anything at all (but no errors). Any idea why? Is there some other way I should be doing this?
Comments
...
During menu rebuild, which happens from time to time, modules' links are written anew to that table. So your changes aren't going to survive.
Doing
$contact['customized'] = 1might solve your problem: Drupal preserves links that were customized.(Another thing to try: immediately after doing menu_link_save(), read from that table and verify that the old link was indeed overwritten.)
The values were written
The values were written (already checked that), but yes, the menu_rebuild() function overwrites them. Where does it get the data from?
Sean Robertson | @seanr1978 on twitter
seanr@webolutionary.com
This code just hosed my site
This code just hosed my site - I now get a 404 on everything including the homepage:
Sean Robertson | @seanr1978 on twitter
seanr@webolutionary.com
This code just hosed my site
This code just hosed my site - I now get a 404 on everything including the homepage:
Sean Robertson | @seanr1978 on twitter
seanr@webolutionary.com
Still no luck with
Still no luck with this:
Doesn't bork the site at least, but it also doesn't do a damned thing. :-(
Sean Robertson | @seanr1978 on twitter
seanr@webolutionary.com
Success!
Got it with this:
Sean Robertson | @seanr1978 on twitter
seanr@webolutionary.com
There are no menu items
This forum post talks about menu links. The other thing hook_menu generates are router items.
--
Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile.