1

Using pathauto module, I know we have a Delete aliases tab to delete URLs in bulk but what if we need to delete URLs of all terms for specific vocabulary?

Any idea how to do that?

  • Might this issue be helpful drupal.org/project/pathauto/issues/870404 – Jdrupal Mar 26 '18 at 8:34
  • you probably need a custom module to do that ... how about updating all aliases of specific vocabulary ? would that help in your end task ? – GiorgosK Mar 26 '18 at 8:47
  • The question is merely, what do you like to achieve with removing the URL aliases? Do you want to "hide" them/make them inaccessible, or do you just want to have the generic URLs of Drupal to be used for this vocabulary? – Mario Steinitz Mar 26 '18 at 9:19
  • @MarioSteinitz I'd have these as generic URLs of Drupal. – usmanjutt84 Mar 26 '18 at 9:33
  • @GiorgosK, good idea – usmanjutt84 Mar 26 '18 at 9:35
2

To delete the aliases you will need a custom module or perhaps a custom VBO action based on the update taxonomy term alias action. Here is a quick and dirty version of a custom module

aliases_delete.info

name = delete aliases
description = will delete vocabulary aliases for specific vocabulary 
package = aliases_delete
version = 1
core = 7.x
dependencies[] = pathauto

aliases_delete.module

<?php

function aliases_delete_menu() {
  $items['aliases_delete/%'] = array(
    'page callback' => 'aliases_delete_delete_vocabulary',
    'page arguments' => array(1),
    'access callback' => 'taxonomy_term_edit_access',
    'access arguments' => array(2),
  );
  return $items;
}

function aliases_delete_delete_vocabulary($vocabulary_name){
  $vocab = taxonomy_vocabulary_machine_name_load($vocabulary_name);
  $terms = entity_load('taxonomy_term', FALSE, array('vid' => $vocab->vid));
  foreach ($terms as $term) {
    pathauto_entity_path_delete_all('taxonomy_term', $term, "taxonomy/term/{$term->tid}");
  }  
  return 'Deleted aliases of all terms in ' . $vocabulary_name;
}

If you enable and install this module you can visit as admin aliases_delete/tags to delete all aliases of terms in vocabulary tags

To update the path aliases of specific taxonomy terms (instead of deleting) you can use VBO - views_bulk_operations

  • install and enable the module
  • create a view of taxonomy terms and use appropriate filters for vocabulary
  • add field "view bulk operations" and save your view
  • go to your view and select all terms that will be updated (VBO can select multiple pages of results)
  • choose the update taxonomy term alias action and press execute
  • all terms should be updated according to the new pathauto rules
  • if I delete the both patterns for the specific vocabulary and the default pattern under the taxonomy patterns, then should this VBO update taxonomy term alias work? In my case it doesn't. – usmanjutt84 Mar 26 '18 at 9:57
  • Aparently when the pattern is empty or it has default path taxonomy/term/[term:tid] the action does not change/update the ALIAS ... what are you looking to achieve ? ... put a specific pattern and it will work – GiorgosK Mar 26 '18 at 10:26
  • taxonomy/term/[term:tid] is a core pattern while I was talking about the admin/config/search/path/patterns like in the image. When I empty these patterns and update as you answered it doesn't update. My ideal achievement is to delete aliases that created by pathauto module. – usmanjutt84 Mar 26 '18 at 10:55
  • updated my answer – GiorgosK Mar 26 '18 at 13:27

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.