You are here

function _do_view_alias_operations in View Alias 5

Same name and namespace in other branches
  1. 6 view_alias.module \_do_view_alias_operations()

create/delete the url aliases for the view and taxonomy term id

Parameters

$view: The view object

$tid: taxonomy term id

$op: one of three operations, VIEW_ALIAS_CREATE_NEW_DELETE, VIEW_ALIAS_DELETE, and VIEW_ALIAS_UPDATE_NOTHING.

1 call to _do_view_alias_operations()
view_alias_admin_settings_submit in ./view_alias.module

File

./view_alias.module, line 216
view_alias.module

Code

function _do_view_alias_operations($view, $tid, $op) {

  // available from token module
  if ($view) {
    switch ($op) {
      case VIEW_ALIAS_CREATE_NEW_DELETE:
        $pattern = $view->url . "/[catpath]";
        $term = taxonomy_get_term($tid);
        $alias = token_replace($pattern, "view_alias", $term);
        path_set_alias("{$view->url}/{$tid}", $alias);
        drupal_set_message("Setting <i>{$alias}</i> as alias for {$view->url}/{$tid}");
        break;
      case VIEW_ALIAS_DELETE:
        $query = "DELETE FROM {url_alias} where src = '%s'";
        db_query($query, $view->url . "/{$tid}");
        drupal_set_message("Removed <i>{$view->url}/{$tid}</i> as an alias.");
        break;
      default:
        drupal_set_message("The operation, {$op}, was attempted, but failed.", "error");
        break;
    }
  }
  else {
    drupal_set_message("View information not found.", 'error');
    return;
  }
}