Skip to content
AtlanticBT Monogram Atlanticbt.com
Menu
March 9, 2012

How to Bulk Delete Filtered Aliases in Drupal 7 without a Module

capabilities covered
Amazon Web Services

The Pathauto module provides a great interface for customizing your URLs, but what happens when you change your mind later? Bulk delete. But you don’t have fine control over limited subsets, you can only delete entire alias types (nodes, taxonomy, etc). Sure you could do this in the database as well — if you have access.

Here’s how to automate clearing out a filtered subset of your alias list (e.g. for a specific taxonomy) from within your browser. There may be modules that probably do this, but I like hacking around in the developer console.

  1. Install Pathauto first :)
  2. Navigate to Configuration » URL aliases
  3. Filter your aliases from the “List” tab
  4. Run the following jQuery snippet in your developer console (F12)

Update: originally restricted context to #block-system-main, it seems that #content is “safer”
[javascript]
(function($){
$deletes = $(‘li.delete a’, ‘#content’);

// loop delete links
$deletes.each(function(i,o){
// jquery
var $o = $(o);

// "click" delete link
$.get( $o.attr(‘href’), function(data){
// get
var $delform = $(data).find(‘#path-admin-delete-confirm’)
, confirm = $delform.attr(‘action’)
;

console.log( $delform.serialize() );
// now "submit" the delete form
$.post( confirm, $delform.serialize(), function(){
console.log( ‘killed ‘ + $o.attr(‘href’) );
}); // submit (post)

}); // click (get)
}); // each

})(jQuery);
[/javascript]

Essentially, it just walks through your list of links, fires each asynchronously, waits for the confirmation form, and then fires that form asynchronously as well.

capabilities covered
Amazon Web Services

The Atlantic BT Manifesto

The Ultimate Guide To Planning A Complex Web Project

Partner With Us

Ready for modern web technology and a sharp, user-friendly design? We want to give you exactly that. Contact us to get started.

Contact
  • This field is for validation purposes and should be left unchanged.