You are here

function rules_action_node_path_alias in Rules 6

Same name and namespace in other branches
  1. 7.2 modules/path.eval.inc \rules_action_node_path_alias()

Action Implementation

Related topics

File

rules/modules/path.rules.inc, line 84
Rules integration for the path module

Code

function rules_action_node_path_alias($node, $settings) {
  $dst = rules_clean_path($settings['dst'], $settings['replace']);

  // Only set the alias if the path alias isn't taken yet.
  if (!drupal_lookup_path('source', $dst)) {
    $node->path = $dst;
    if (user_access('create url aliases') || user_access('administer url aliases')) {

      // Path module is going to save the alias on node save.
      return array(
        'node' => $node,
      );
    }
    else {
      path_set_alias('node/' . $node->nid, $node->path, isset($node->pid) ? $node->pid : NULL, isset($node->language) ? $node->language : '');
    }
  }
}