You are here

function rules_action_path_alias in Rules 7.2

Same name and namespace in other branches
  1. 6 rules/modules/path.rules.inc \rules_action_path_alias()

Action implementation: Path alias.

Related topics

1 string reference to 'rules_action_path_alias'
rules_path_action_info in modules/path.rules.inc
Implements hook_rules_action_info() on behalf of the path module.

File

modules/path.eval.inc, line 15
Contains rules integration for the path module needed during evaluation.

Code

function rules_action_path_alias($source, $alias, $langcode = LANGUAGE_NONE) {
  if (!$alias) {
    path_delete(array(
      'source' => $source,
      'language' => $langcode,
    ));
  }
  elseif (!$source) {
    path_delete(array(
      'alias' => $alias,
      'language' => $langcode,
    ));
  }
  elseif (!path_load(array(
    'alias' => $alias,
    'language' => $langcode,
  ))) {

    // Update the existing path or create a new one.
    if ($path = path_load(array(
      'source' => $source,
      'language' => $langcode,
    ))) {
      $path['alias'] = $alias;
    }
    else {
      $path = array(
        'source' => $source,
        'alias' => $alias,
        'language' => $langcode,
      );
    }
    path_save($path);
  }
  else {
    rules_log('The configured alias %alias already exists. Aborting.', array(
      '%alias' => $alias,
    ));
  }
}