0

Here is my problem.

  1. I have created a view with path as groups/% where % is a term id.
  2. Now, i would like to create auto aliases for all groups/% with % as a term name.

Ideally i would like to add this alias path on creation of a term related to particular vocabulary. Is there any module that will do this out of the box ?

PATH AUTO MODULE: As far as i know it allows to set patterns only for taxonomy term paths and node paths for different content types.

But, how to set patterns for custom menu paths ?

3 Answers 3

1

I am not sure whether we should take this way or not but I found this:

We can save new path alias using path_save() function.

Here is how I managed it:

I called the function after submission of node or group node.

Then I called a custom function and fetch the real URL of the node i.e in your case it will be group/tid.

Now I retrived term name from term id and created new alias with term name.

Called path_save() function with necessary information.

1

Solved it 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));
  }
}
0

You can use one of these modules to do this in Drupal 7 for all the Custom Paths whether they are created from custom modules OR from Views/Blocks:

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .