Change a Drupal Menu Item's Path Before Unpublishing Its Node

This article was published by DrupalEasy as a Quicktip, .

Drupal developers of every level of experience understand that a menu item can point to any valid path, such as that of a node. But Drupal beginners can receive a nasty shock when they discover — usually the hard way — that changes to such nodes can result in unplanned and unpleasant changes to menus. Specifically, one of the more annoying traits of Drupal is the way a menu item disappears when its associated node is unpublished (or deleted, i.e., unpublished with extreme prejudice). This may be old news to Drupal veterans, but people new to this CMS can easily stumble into this pitfall. When you are focused upon fine-tuning the contents of a website, it is easy to forget that a particular node is the target of a menu item, and then unpublish it. The consequences may be clear only later when your client or a website visitor notices that the menu is missing an entry. Or you may be the one who notices, moments later, when trying to locate the menu item, in order to point it to a different node.

One could argue that this automatic menu item deletion is proper behavior, because otherwise, what would the menu item link to? But I think that it would be more helpful if Drupal either (1) left the menu item as is, and displayed a "Page not found" error to any user who clicked on that menu link, or (2) automatically changed the menu item path to <front>. Additionally, Drupal could warn you that the menu item no longer points to any valid destination. This would preserve your intended menu structure, and consequently allow you to point that menu item to an existing node or a new one, or intentionally remove the menu item. Instead, Drupal silently deletes the item from the menu, potentially wrecking your menu structure, without providing any warning beforehand or notification afterward.

Regardless of one's opinion on the matter, one cannot dispute the value of the following practice: If you want to retain a menu item and point it to a different node, then make that change to the path first before unpublishing the original node.

Copyright © 2011 Michael J. Ross. All rights reserved.
bad bots block