There's two ways to bulk generate/regenerate aliases with Pathauto:

  1. Via the dedicated form at /admin/config/search/path/update_bulk
  2. 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.

Issue fork pathauto-3086634

Command icon 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

bkosborne created an issue. See original summary.

bkosborne’s picture

Here's the code in the bulk action, it's just two lines:

$entity->path->pathauto = PathautoState::CREATE;
\Drupal::service('pathauto.generator')->updateEntityAlias($entity, 'bulkupdate', ['message' => TRUE]);

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 =/

bkosborne’s picture

Another 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.

Lutfiyeturan’s picture

Hi, 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.

axroth’s picture

Status: Active » Needs review
alessons’s picture

StatusFileSize
new24.86 KB

Sorry, 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.

deaom’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

berdir’s picture

Status: Reviewed & tested by the community » Needs work

That 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.

mably’s picture

Status: Needs work » Needs review

Seems like the most logical option we have here:

Maybe we need 3 actions that mimic the three options available on the dedicated alias regen form, but it's tricky to label them =/

mably’s picture

Status: Needs review » Needs work

mably’s picture

Assigned: Unassigned » berdir
Status: Needs work » Needs review

Minimal fix: stop forcing PathautoState::CREATE in the bulk action

The root cause is that UpdateAction::execute() forcibly sets $entity->path->pathauto = PathautoState::CREATE before calling updateEntityAlias(). 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:

if ($entity->path->pathauto != PathautoState::CREATE && empty($options['force'])) {
  return NULL;
}

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.

mably’s picture

Alternatively, 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;.

anybody’s picture