Pathauto shouldn't allow the creation of duplicate aliases

Created on 29 August 2024, 3 months ago

Problem/Motivation

Pathauto does take some steps to prevent alias duplication in the PauthautoGenerator::createEntityAlias however if someone alters the path_alias in hook_path_alias_presave() it's possible they could still create a duplicate. One common example is to set the langcode for the default language to und, so that all translations can share the same alias. This can create a duplicate alias everytime someone saves a node in the default language if you are using the patch in https://www.drupal.org/project/pathauto/issues/3113395 Prevent redundant alias update caused by path alias language fallback. Needs review and setting the language to und, as the AliasStorageHelper::loadBySource method won't fall back to undefined anymore if the current entity langcode isn't found for that alias.

Steps to reproduce

* Use the patch in https://www.drupal.org/project/pathauto/issues/3113395 Prevent redundant alias update caused by path alias language fallback. Needs review
* Create a hook_path_alias_presave hook that sets any alias saved in the default language to und.
* Resave the node, it will always see the alias as new because you alter the langcode after the duplicate checks have been completed.
* Alternatively just create a duplicate programmatically.

Proposed resolution

Throw an EntityStorageException if a duplicate is found in a presave hook and log a warning.

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

achap 🇦🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024