6

I have a lot of programmatically generated nodes with the option "Generate automatic URL alias" unchecked, so i can't use the Bulk Update of the pathauto module.

How can i to bulk generate the pathauto alias for these nodes?

Edit: i use Drupal 7

8 Answers 8

6

Have you tried using Views Bulk Operation. All you will need to do is create a view that will list all the nodes that will meet your criteria and then assign an action 'Generate Url alias' (I haven't tried it though.)

3
  • 3
    This method does not work if the 'generate url alias' option in not enabled on the existing node's node edit form. Which seems to make VBO useless in the situation that you have a lot of existing nodes for which the 'generate url alias' option was not enabled.
    – Benjen
    Feb 4, 2016 at 6:23
  • This isn't the correct answer for the reasons Benjen explained. I'm having the same problem.
    – Christia
    May 20, 2017 at 0:33
  • Agreed it won't work for entities with Generate URL Alias unchecked. To work around this, you'll need to manually update the table that tracks that checkbox's state with sql. In latest D7 pathauto 7.x-1.3, that's pathauto_state. Two examples are below: One is for updating existing records, the other is for inserting new records where they don't yet exist. Jul 13, 2019 at 14:12
7

VBO doesn't have an option to change the status of 'Generate automatic URL alias'

You could execute the following mysql query:

UPDATE `pathauto_state` SET `pathauto`=1 WHERE `entity_type` = 'node'

Or if you want to update just exact content type only:

UPDATE  `pathauto_state` p, `node` n SET `pathauto` = 1 WHERE
p.entity_id = n.nid and n.type = 'mycustontype'

where 'mycustomtype' is a machine name of the content type.

Or if you have drush installed:

drush sqlq "UPDATE pathauto_state SET pathauto=1 WHERE entity_type = 'node'"

After that you can bulk generate the new paths as you would normaly do on: admin/config/search/path/update_bulk

1
  • Thank you! This is the correct answer. Using VBO doesn't work to update path alias unless path alias is already selected.
    – Christia
    May 20, 2017 at 0:45
2

In addition to Rick B's answer, you will also need to create entries for the nodes that have never had that checked. That can be accomplished running this query:

INSERT INTO pathauto_state
SELECT 'node',n.nid ,1
FROM node n
WHERE n.type = 'api'
AND n.nid NOT IN (SELECT entity_id FROM pathauto_state)

which can be run either using drush on directly on the database as Rick described.

For taxonomy terms, determine your term's vocabulary id (3 in the example below) and do a similar insert:

INSERT INTO pathauto_state
SELECT 'taxonomy_term', t.tid, 1
FROM taxonomy_term_data t
WHERE t.vid = 3
AND t.tid NOT IN (SELECT entity_id FROM pathauto_state)
1

I can verify this works with Views Bulk Operations (VBO).

Just tried what Gokul N K mentioned because I ran into the same problem and I can verify it still works with actual module versions.

I had existing taxonomy terms with unchecked “Generate automatic URL alias” and I wanted to update them in bulk.

My setup below: Drupal 7 (7.34) with Views (7.x-3.8), Pathauto (7.x-1.2) & VBO (7.x-3.2). I assume the modules present / installed configured.

  1. deleted all taxonomy term aliases /admin/config/search/path/delete_bulk
  2. created a new view under /admin/structure/views and selected (Show) Taxonomy terms (in my case I selected all for all vocabularies, you could choose a certain vocab only)
  3. select "fields" under "Display format", make more adjustements if necessary, then "Continue & edit"
  4. Under fields, hit "add" and search for "Bulk operations: Taxonomy term", check and apply
  5. then check "Update taxonomy term alias" and apply
  6. Save your view and head to the views location and bulk update all taxonomy term path aliases
1

For those of you that need this to be in php form for using in a module/theme/etc really quick:

<?php
$update_auto_aliases = db_update('pathauto_state')
  ->fields(array(
    'pathauto' => 1,
  ))
  ->condition('entity_type', 'node', '=')
  ->execute();
?>
1

In my case (for Drupal10 ) bulk update was not generating aliases due to the fact that all the nodes (when you edit a node) had unchecked the checkbox "generate automatic alias". I have found a quick workaround (which I recommend when you have less than a few hundreds nodes). Go to /admin/content and from there select the nodes to be updated and make sure to select "Update Url alias" in the action dropdown (below the filters) and then click "Apply to selected items".

0

You need to delete the aliases for those previously created nodes before assigning them new aliases. This post explains how to do that.

1
  • I am using Drupal 7, not 5 or 6. Anyway in Drupal 7 the content of the link can be done from admin panel selecting a proper configuration. I am trying to bulk assign an alias to nodes that have the option "Generate automatic URL alias" unchecked Sep 7, 2012 at 9:56
0

I think this can be done with Drupal 8 and VBO (at least it worked for me) - using the "Modify field values" action - because "Generate automatic URL alias" is just a field automatically provided for each item of content. The caveat is that you'll have to do it for each content type, but this can all be done on the same form as follows :-

  1. Select the items in the VBO listing required (or Select all)
  2. Choose the "Modify field values" action
  3. Click "Apply to selected items" button
  4. Expand each content type you want to apply this to and tick the "URL Alias" checkbox. The expanded form should then show a "Generate automatic URL alias" checkbox. This defaults to ticked so you don't have to do/change anything. Don't press the Submit button yet...
  5. After doing step #4 for each content type press the submit button.

I didn't get a confirmation message afterwards (which is disconcerting - probably a bug in the excellent VBO module) but it did work for me (presumably in the background batch job).

1
  • The question was tagged for Drupal 7. Also, it was 7 years ago and it was legit to use Drupal 7 Oct 17, 2019 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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