Drupal breadcrumbs implementation is a never-ending source of frustration for many website developers. A few modules exist which more or less successfully attempt to get Drupal to display meaningful breadcrumbs on every page.
One of these modules is menu_breadcrumb, which displays the breadcrumb trail based on current node's menu path. Very useful and sufficient in most use cases.
The only problem with menu_breadcrumb is when you're not happy to grant users the administer menu permission to create and assign menu items for the content they create.
Several Drupal modules exist which work around the permission restriction and automatically create menu items for newly created content nodes. To name a few, Auto Menu and Automatic Menu, both of which are either only available for Drupal 5.x, or their Drupal 6.x implementation is still in beta development stage.
Fortunately, a quick and easy way to create menu items programmatically doesn't even require a standalone module. All we're going to need is the Rules module and a bit of Drupal API knowledge.
The Rules set of modules allows site administrators to define conditionally executed actions, such as arbitrary PHP code execution, based on occurring events, such as node creation. For the Drupal API part, we'll use a single function menu_link_save.
menu_link_save requires an item configuration parameter, whose key names mirror the column names of Drupal's menu_links database table.
As mentioned above, we're going to use the Rules module. It's installation is pretty straightforward and requires no additional configuration. Let's move right to the setting up our rule.
Say we want to create a menu item under Primary Links menu's Blog item every time a new node of type Story is created.
Navigate your browser to Administer » Rules » Triggered rules page, add a new rule and configure it along the lines of the image:
Finally, we're getting to the PHP snippet itself, which we'll use to automatically create a new menu item every time this rule is triggered. Click Execute custom PHP code and insert the following fragment of code:
$item = array( 'link_path' => 'node/' . $node->nid, 'link_title' => $node->title, 'plid' => 426, 'hidden' => 1 ); menu_link_save($item);
Just a few remarks on otherwise pretty simple piece of code.