You are here

function pathauto_taxonomy in Pathauto 5

Same name and namespace in other branches
  1. 5.2 pathauto.module \pathauto_taxonomy()
  2. 6.2 pathauto.module \pathauto_taxonomy()
  3. 6 pathauto.module \pathauto_taxonomy()

Implementation of hook_taxonomy().

File

./pathauto_taxonomy.inc, line 46

Code

function pathauto_taxonomy($op, $type, $array = NULL) {
  switch ($type) {
    case 'term':
      switch ($op) {
        case 'insert':
        case 'update':

          // Use the category info to automatically create an alias
          $category = (object) $array;

          // Work-around for the different structure of the third parameter
          // between Drupal 4.7.x and 5.x hook_taxonomy(). This allows us to
          // use a single, clean catpath helper function.
          $category->parent = $category->parent[0];
          if ($category->name) {

            // Generate the placeholders for this vocabulary.
            $placeholders = array();
            $vid = $category->vid;
            $vocabulary = taxonomy_get_vocabulary($vid);
            $placeholders[t('[vocab]')] = pathauto_cleanstring($vocabulary->name);
            $placeholders[t('[cat]')] = pathauto_cleanstring($category->name);
            $placeholders[t('[tid]')] = $category->tid;
            $catpath = '';
            $placeholders[t('[catpath]')] = _pathauto_taxonomy_catpath($category);

            // Append any additional extensions
            $extplaceholders = module_invoke_all('pathauto_taxonomy', 'values', $category);
            $placeholders = array_merge($placeholders, $extplaceholders);

            // Create the taxonomy term alias.
            $src = taxonomy_term_path($category);
            $alias = pathauto_create_alias('taxonomy', $op, $placeholders, $src, $vid);

            // If we're in a forum vocabulary, also create a forum container, forum, or forum topic alias.
            if (module_exists('forum')) {
              $forumvid = variable_get('forum_nav_vocabulary', '');
              if ($vid == $forumvid) {
                $src = 'forum/' . $category->tid;
                $alias = pathauto_create_alias('forum', $op, $placeholders, $src, $vid);
              }
            }
          }
          break;
        case 'delete':

          //If the category is deleted, remove the path aliases
          $category = (object) $object;
          path_set_alias('taxonomy/term/' . $category->tid);
          path_set_alias('forum/' . $category->tid);
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }
}