You are here

function _pathauto_menu_link_update in Pathauto Menu Link 7

Update the path for a node menu link.

Parameters

object $link: The link.

2 calls to _pathauto_menu_link_update()
pathauto_menu_link_menu_link_update in ./pathauto_menu_link.module
Implements hook_menu_link_update().
_pathauto_menu_link_update_children in ./pathauto_menu_link.module
Search for and update any child menu links.

File

./pathauto_menu_link.module, line 22
Update paths when a menu item is moved.

Code

function _pathauto_menu_link_update($link) {
  $exploded = explode('/', $link['link_path']);
  if ($exploded) {

    // Only affect nodes.
    if ($exploded[0] == 'node' && isset($exploded[1]) && is_numeric($exploded[1])) {

      // Get the node ID and load the node object.
      $nid = $exploded[1];
      if (!is_numeric($nid)) {
        return;
      }
      $node = node_load($nid, NULL, TRUE);
      if (is_bool($node)) {
        return;
      }

      // @todo: Check that the path has changed before updating the node.
      // Update the alias.
      pathauto_node_update_alias($node, 'update');

      // Update any child menu links.
      _pathauto_menu_link_update_children($link);
    }
  }
}