There's two ways to bulk generate/regenerate aliases with Pathauto:
- Via the dedicated form at /admin/config/search/path/update_bulk
- Via the content overview page, there's a views bulk action "Update URL alias"
The first method gives the user several options with how to generate the aliases.
The second method doesn't.
Under the hood, the second option will perform a forced regen of the alias, even if the node has "Generate automatic URL alias" unchecked. This means that any custom aliases that were provided for a node would be wiped out and replaced with the auto generated one based on the pattern for that content type.
This feels dangerous to me.
I propose that this be changed so that it only updates aliases for nodes that are already letting pathauto manage the alias. Other nodes should be ignored.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | Screenshot from 2021-06-03 08-54-41.png | 24.86 KB | alessons |
| #4 | bulk-action-ignore-custom-aliases-3086634-4.patch | 718 bytes | Lutfiyeturan |
Issue fork pathauto-3086634
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
bkosborneHere's the code in the bulk action, it's just two lines:
I suspect this was done so that content managers can bulk generate aliases for existing content after the pathauto module was enabled, or after a pattern was created. In those cases, those nodes would not have been set to have their aliases managed by pathauto, so this action provides a way to bulk generate them. But even in these cases, the node will still have the "Generate automatic URL alias" disabled for the node after the alias was regenerated, because the
$entity->path->pathauto = PathautoState::CREATE;doesn't actually persist to the node and get saved!I still think this is unexpected behavior for sites that are using it to simply regen an alias after a pattern needs to be re-evaluated since it will overwrite custom aliases.
Maybe we need 3 actions that mimic the three options available on the dedicated alias regen form, but it's tricky to label them =/
Comment #3
bkosborneAnother option is to only generate the alias for nodes that are not set to use pathauto only if the node does not already have an alias. That way you wouldn't be wiping out any custom aliases that were set.
Comment #4
Lutfiyeturan commentedHi, adding a patch to ignore custom aliases by checking if the "Generate automatic URL alias" checkbox is 1 or 0 ($entity->path->pathauto).
The alias should be regenerated only if the checkbox is enabled.
Comment #5
axroth commentedComment #6
alessons commentedSorry, I've tried run the error but it was unsuccessfully.
#4 how do you tested the issue before do the fix?
I've created 3 articles and put 1 manual label ( Generate automatic URL alias unchecked), after this I've tried to change another URL alias manually.
Comment #7
deaom commentedI can confirm the issue and also that the patch applies and works. My steps to reproduce:
1. add a node title pattern for all content types
2. create two nodes
3. on one enable the generate automatic URL alias, an on the other disable it and write custom url alias and save the node.
4. go to content, select all nodes, from dropdown select update URL alias and check what happens
Before the patch the node with custom url alias get regenerated to the node:title pattern.
After the patch the node with custom url alias does not get regenerated and the custom url alias stays.
I also enabled the custom generation for all nodes and tested with patch enabled, and the node did get the url alias regenerated, which means it works as it should.
Marking it as RTBC, but maybe maintainers will want some tests.
Comment #8
berdirThat flag is not a boolean, it just happens to have the values 0 and 1. And the result should be the same if the explicit overwrite of ->pathauto is just removed.
Comment #9
mably commentedSeems like the most logical option we have here:
Comment #10
mably commentedComment #12
mably commentedMinimal fix: stop forcing PathautoState::CREATE in the bulk action
The root cause is that
UpdateAction::execute()forcibly sets$entity->path->pathauto = PathautoState::CREATEbefore callingupdateEntityAlias(). This overrides the entity's actual pathauto state, so even entities with custom aliases (state = SKIP) get their aliases regenerated.The fix simply removes that line. Without it,
updateEntityAlias()checks the entity's real pathauto state:So entities where the user unchecked "Generate automatic URL alias" (state = SKIP) are now correctly skipped by the bulk action, preserving their custom aliases.
This is the minimal fix — one line removed — and it aligns the Views bulk action behavior with the dedicated bulk update form at
/admin/config/search/path/update_bulk, which already respects the pathauto state when using the "Generate a URL alias for un-aliased paths only" option.Comment #13
mably commentedAlternatively, we could update the action label to explicitly state that manually defined aliases will also be overridden.
And replace the use of
$entity->path->pathauto = PathautoState::CREATE;with$options['force'] = TRUE;.Comment #14
anybodyOnce #3068140: Add action to allow bulk changing of "generate automatic URL alias" option is in, the user has full control with the two actions combined.