Bulk generate won't work if the existing nodes or terms didn't enable "Generate automatic URL alias". The work around for assigning alias to existing content is to do bulk "Update URL-Alias" at /admin/content. But there is no way to bulk enable "Generate automatic URL alias" for taxonomy terms. It would be nice to have bulk enable "Generate automatic URL alias"/force option in bulk generate so existing content/terms can have alias assigned to them.
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | Screen Shot 2019-11-09 at 11.32.16.png | 125.66 KB | berramou |
| #19 | add_bulk_enable-2660640-19.patch | 5.18 KB | juampynr |
| #17 | add_bulk_enable-2660640-17.patch | 5.03 KB | juampynr |
| #16 | add_bulk_enable-2660640-16.patch | 3.35 KB | juampynr |
| #16 | interdiff.txt | 1.88 KB | juampynr |
Comments
Comment #2
meichr commentedHi Weilinggu,
this feature is already implemented, you find it at the "Content" page (Drupal 7 as well as Drupal 8). You can read about it in the documentation (How does Pathauto determine if the 'Automatic URL alias' checkbox should be checked or not?) about Pathauto, here is an excerpt for the D7 version, but it applies also to D8, when you use the "Content" menu or admin/content as the url (url in the D7 documentation does not work in D8):
"If you have content you've created before installing Pathauto that you would like to ensure that the checkbox is checked whenever you edit them, then you should use the 'Update URL alias' bulk action on your content listing admin page (admin/content
/node)."Though there seems to be a problem, as it creates an URL alias for the checked content, but doesn't seem to update the cache like the individual URL-Alias update in the node edit would do. Workaround for the time being: command "drush cr" on the shell after the bulk creation, if you have drush installed or clear the cache on the admin/config/development/performance page.
Regards.
Comment #3
mstrelan commentedThe OP already knows how to do this for nodes and wants to know how to do this for taxonomy terms.
Comment #4
progzy commentedThis is not entirely true by default because of pagination. If one has more than 50 items to update it will only update the first 50 items. I don't know if there is a workaround for this (in D7, the system proposed to perform the operation for the remaining items - with VBO module AFAIR).
So IMHO I would not consider that the feature is already implemented. I then agree with the request.
Comment #5
meichr commentedThanks mstrelan and progzy, you are right. A force option would solve the problem for nodes and taxonomy terms. I now also think this feature request would be good to have in pathauto.
Comment #6
berdirHuh, almost lost my comment, d.o just ignored it. Trying again...
There are two issues here.
The problem most if you are running into is a problem with the new pathauto state feature that's not working as intended yet. The idea is that it allows to *explicitly* opt out of aliases for certain entities and not have bulk generate or other re-saving re-generate it for them.
However, something there doesn't work correctly yet for entities that were created before there were pattern, it should still generate it from them. This behavior is actually a bug. And I think fixing that would solve the problem for most people.
Having a force option to even override those that explicitly opted out would be a feature on top of that, but I'm not sure that's really needed once the bug is resolved.
What would help to move this forward is writing tests. We have bulk generate tests, it should be possible to alter them to reproduce this behavior.
The code for this is in PathautoState.
Comment #7
juampynr commentedHere is a patch with a test and another patch with the test and the fix.
Comment #12
juampynr commentedOkay, now I see what is the logic that I removed doing. The test seems valid though. I will continue debugging.
Comment #13
berdirHave you seen (and tried) https://github.com/md-systems/pathauto/issues/121#issuecomment-172396101 ?
Comment #14
mariancalinro commentedHere's a patch that implements the force option, if it's decided that it's needed.
Comment #15
juampynr commentedCopied from https://github.com/md-systems/pathauto/issues/121#issuecomment-172396101:
Comment #16
juampynr commentedHere is an alternative version based on what I learnt at #2655874: Improve error handling for "The given alias pattern always matches the route". Let's see what tests say.
Comment #17
juampynr commentedHere is a new patch that includes the test from #2654990: Not possible to save custom alias when no pattern is configured, as it fixes that issue too.
Comment #18
berdirYes, this might work, actually.
So in case we don't have an explicit state, we do it based on whether we are able to create an alias or not, not whether we actually have one that matches.
would be good to have an OK from @davereid on this.
comment needs to be updated. and it actually looks like that pretty much already provides test coverage.
Comment #19
juampynr commentedAdjusted test comment as suggested. I have notified Dave Reid to chime in here.
Comment #21
berdirWe can still make adjustments, but this solves a ton of problems and goes in the right direction. Committed!
Comment #23
ceefour commentedUsing Drupal 8.1.6 and pathauto 8.1.0-alpha3.
I'm also using Content Translation with 2 languages.
This issue still persists.
"Generate bulk aliases" doesn't create aliases for any of my taxonomy terms.
Especially after "Delete aliases".
I need to edit each term and check "generate alias" one by one. :(
Comment #24
webservant316 commentedI ran into this problem today. I had programmatically created hundreds of nodes, but the 'Generate automatic URL alias' flag was not explicitly set which caused pathauto to use its own logic to determine whether or not to create a new path alias on update. This was fine on the initial creation because aliases were created as expected. However, if I changed something that required the alias to be rewritten, it would not rewrite because the new alias was different than the existing and the pathauto flag was not explicitly set.
So first I fixed my code for programmatic code generation adding this line...
Next I had to deal with existing nodes that did not have the pathauto flag set. As this issue post says there is no way to do that. So I had to force the issue with a little bit of code.
With this temporary function in place I ran the bulk update alias operations on my nodes... twice. The first time updated any aliases it could and also assigned pathauto=TRUE if not already set for all nodes. The second pass updated all the remaining aliases. When completed I removed the hook above.
It would be nice if pathauto offered a bulk operation to edit the pathauto flag on each node. However, until then you could use the above as I did. You could add conditions to the function above or simply use it as is and only run bulk update on all or a subset of the nodes that concern you.
I am using Drupal 7, but I didn't see a related issue in the 7 queue.
Comment #25
sjhuskey commented#24 worked for me. Thank you very much!
Comment #26
salvadorp commentedHello,
I had a similar issue, with a Drupal 8.6 with lots of nodes without the pathauto check enabled, and I needed to re-generate all the aliases.
In order to enable this check in all the nodes:
Search in "key_value" table for the key "pathauto_state.node".
Then changed the value from i:0 to i:1 with a SQL Update.
In my case I needed to update all the nodes of all types, but in a specific case it can be filtered.
Maybe there is another way, but I didn't find it for bulk updates in order to enable this pathauto flag on nodes.
Comment #27
berramou commentedThanks @SalvadorP it works perfectly for nodes.
But doesn't work for user, i did change
pathauto_state.usertoi:1but it doesn't work.There is any other way for users?
Comment #28
salvadorp commentedHi @berramou,
I'm not sure about users, but maybe with this line on hook_entity_presave():
I'm using this to set the pathauto on each node creation or update.
Using that in presave hook you may be able to set the pathauto for any entity.
Maybe you can find a bit more info or an idea in this issue https://www.drupal.org/project/pathauto/issues/2946273.
Comment #29
berramou commentedHello @SalvadorP thank you for your replay.

I had another issue, Pathauto generate alias only for original language even if you don't select any language in the alias configuration.
With the config below, pathauto should generate the alias for all language e.g:
en/utilisateur/1
fr/utilisateur/1
es/utilisateur/1
ar/utilisateur/1
I had to bypass it with:
Now bulk operation generate alias for all languages.
I don't know is this normal behavior or it's an issue?
Comment #30
erier commentedThe problem
What does the code do?
I understand why there is no option to turn on 'automatically generate url alias' for all nodes of a certain type, because what if you only want a certain batch of them based on some condition to have the option turned on.
The solution above was a quick way to turn on 'generate automatic url alias' for ALL nodes in a content type.
Comment #31
philyThanks to SalvadorP for comment #26 which was (for me) the easiest to setup (commerce_product entity).
Comment #32
mlncn commentedPathauto in Drupal 8/9 has an "Update URL Alias" action that can be used from the /admin/content page to bulk update all nodes, or nodes of a given content type, to use their configured pathauto pattern.
Tested this for nodes that had not gotten their aliases from a bulk generate and it worked.
Practically speaking if you want to do more than 50 nodes at a time you'll want https://www.drupal.org/project/views_bulk_operations
Comment #33
mlncn commentedTried to make a module and it didn't work out but here's a MySQL/MariaDB query to do this for people:
UPDATE node AS n INNER JOIN key_value AS kv ON n.nid=kv.name LEFT JOIN path_alias AS pa ON CONCAT('/node/', n.nid)=pa.path SET kv.value='i:1;' WHERE kv.collection='pathauto_state.node' AND kv.value='i:0;' AND pa.alias IS NULL;Comment #34
liquidcms commentedCame across this nightmare left over from Drupal versions of yesteryears and i see still can't properly force url aliases being set.
- none of the bulk generate options work
- Using VBO and views bulk edit, it allows setting the "Generate URL Alias" checkbox - but doesn't work
- there is no Update URL Alias action available (to VBO)
but then came across this post and it reminded me that in D8/9 we have 2 types of actions (so annoying) VBO compatible ones and Core ones. Sure enough the action is there in a core bulk update view and it does work.. yay.. Of course, as just mentioned above.. only good if you want to do a page at a time.
Pretty sure this should not be marked as fixed as there is no proper solution for this.
Comment #35
w01f commentedJust noting I also just caught up on this, and still find the current system of config and options convoluted and confusing.
Comment #36
lubwn commentedIn Drupal Commerce site, if you happen to add Pathauto to products a bit late and want to check "Generate URL Alias" for all the products place this code in any theme hook function and reload website ONCE, then remove the code and you are good to go.
I think this could be easily made to a contrib module or maybe just a snipplet in documentation would work.
Comment #37
wranvaud commented@lubwn you could use an update hook instead that let's you do bulk updates without timing out if you have many entities and you can also leave the code because it will only execute once on each environment.
Comment #38
vegardjo commentedUsing Drupal 10.4, and running the "Update URL Alias" action does not enable the "Generate automatic URL alias" setting on the nodes, so I also don't see that this is a closed task..?
I did this for a one off, test locally and use at own risk!
Comment #39
efpapado commentedFollowing up vegardjo's suggestion, another code snippet that does not trigger a node save:
This only updates the key_value table, which immitates the
class PathautoState's logic.And here too: use at own risk!