You are here

function nodesymlinks_item_alias_save in NodeSymlinks 6

Same name and namespace in other branches
  1. 7 nodesymlinks.inc \nodesymlinks_item_alias_save()

Create alias for duplicate menulink if original node.

Parameters

item $item:

node $node:

Return value

bool

1 call to nodesymlinks_item_alias_save()
nodesymlinks_item_save in ./nodesymlinks.inc
Save item to database, create alias for duplicate menulink if original node has one. Returns TRUE if saving was successfull, else returns FALSE.

File

./nodesymlinks.inc, line 626

Code

function nodesymlinks_item_alias_save(&$item, &$node) {

  // Integrate with Path module.
  if (module_exists('path')) {

    // We need to know pid to provide "update" otherwise Path creates new
    // alias to the same path.
    $pid = !empty($item['alias']['pid']) ? $item['alias']['pid'] : NULL;

    // Integrate with Pathauto module.
    if (module_exists('pathauto')) {

      // Handle Pathauto alias.
      if (!empty($item['alias']['pathauto']) || empty($item['alias']['path'])) {
        $op = $item['is_new'] ? 'insert' : 'update';
        _nodesymlinks_include('pathauto');
        return nodesymlinks_pathauto_create_alias($item, $node, $op);
      }
      else {
        return path_set_alias($item['link_path'], $item['alias']['path'], $pid, $node->language);
      }
    }
    elseif (!empty($item['alias']['path'])) {

      // Save custom path alias.
      return path_set_alias($item['link_path'], trim($item['alias']['path']), $pid, $node->language);
    }
    else {

      // Create and save default alias based on node path.
      $path_alias = empty($node->path) || $node->path == 'node/' . $node->nid ? '' : $node->path . '_' . $item['mlid'];
      return path_set_alias($item['link_path'], $path_alias, $pid, $node->language);
    }
  }
}