1

I set up a view with taxonomy id as the argument and am trying to figure out how to alias the term id with its name.

Trying to turn url.com/discussion/8 -> url.com/discussion/term but the argument must still be the id b/c I need to to pass it by URL to a node edit form from a link on the view display.

1

In your View, check the taxonomy argument and set the validator to Taxonomy Term. From there you can specify the argument type (and vocabulary where the term is expected to come from). Set the argument type to "Term name/synonym converted to Term ID" and that should help.

  • Any chance of a response on this? Did the suggestions provided work? – user1731 Oct 2 '12 at 4:27
1

I came across same issue solved it with below code ! Hope it helps ! You need to write a small custom module to do this !

Using hook term insert update delete and pathauto helper function.

/**
 * Implements hook_taxonomy_term_insert().
 */
function your_module_taxonomy_term_insert($term) {
  // Do it only for Group Categories term
  if ($term->vid == 3) {
    module_load_include('inc', 'pathauto');
    $path = array();
    $path['source'] = 'groups/' . $term->tid;
    $path['alias'] = pathauto_cleanstring($term->name);
    path_save($path);
  } 
}

/**
 * Implements hook_taxonomy_term_update().
 */
function your_module_taxonomy_term_update($term) {
  // Do it only for Group Categories term
  if ($term->vid == 3) {
    module_load_include('inc', 'pathauto');
    $conditions = array();
    $conditions['source'] = 'groups/' . $term->tid;    
    $path = path_load($conditions);    
    // Delete old alias if user erased it.
    if (!empty($path['pid'])) {
      path_delete($path['pid']);
    }
    $path = array();
    $path['source'] = 'groups/' . $term->tid;
    $path['alias'] = 'groups/' . pathauto_cleanstring($term->name);
    path_save($path);
  }
}

/**
 * Implements hook_taxonomy_term_delete().
 */
function your_module_taxonomy_term_delete($term) {
  // Do it only for Group Categories term
  if ($term->vid == 3) {
    path_delete(array('source' => 'groups/' . $term->tid));
  }
}

Note: Replace 3 with the vocabulary id you are using Replace source pattern 'groups/' . $term->tid and alias pattern with the patterns you would like to.

Hope it helps !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.