API documentation does not indicate 2 important steps when calling menu_link_save() in a custom module:

  1. Users should normalize the link_path key using drupal_get_normal_path before passing it into menu_link_save()
  2. Also, in order for the newly saved link to work, will need to clear the menu cache by calling menu_cache_clear_all() afterward

More details can be found at: http://api.drupal.org/api/drupal/includes--menu.inc/function/menu_link_s...

Comments

kim-day’s picture

Assigned: kim-day » Unassigned
Status: Active » Needs review
StatusFileSize
new756 bytes

Here's a patch

jhodgdon’s picture

Title: Documentation problem with menu_link_save() » menu_link_save() needs more detail
Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work

This doc addition seems like a reasonable idea.

The patch needs a small amount of work:
a) There are spaces at the ends of a few lines - those need to be removed.
b) I'm not sure what "custom code" is as opposed to other types of code? I think you could just say "After calling this function, rebuild...".
c) It would be nice to bring this documentation up to standards while you're in here, by also fixing the first line: Save -> Saves.
d) And maybe it would also be nice to fix up the @param section to something like this:

An associative array representing a menu link item, with elements:
- link_path: (required) The path of the menu item, which should be normalized ...
- link_title: (required) The title of the menu item.
- menu_name: (optional) The machine name of the menu to put the link in (defaults to 'navigation').
(etc.)

See http://drupal.org/node/1354#lists and http://drupal.org/node/1354#functions for (d) and (c) respectively.

Thanks!

jn2’s picture

Status: Needs work » Needs review
StatusFileSize
new2.17 KB

Here's a patch incorporating suggestions from comment #2.

kim-day’s picture

Status: Needs review » Reviewed & tested by the community

Thanks jhodgdon for the detailed feedback and jn2 for making the changes. The patch works correctly so I'm marking rtbc.

jhodgdon’s picture

+1 for RTBC for d8 and d7. Thanks kim-day and jn2!

dries’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the clarifications. Committed to 7.x and 8.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.