In PathWidget, the validator will try to validate if the alias is unique without a chance for PathautoGenerator to uniquify the value. This introduces a problem when trying to translate an entity with an alias, the validator will trigger because the alias is not empty.

Steps to reproduce:

  1. Create a node 'A' with the alias "/path/foo" in English
  2. Create another node 'B' and with the alias "/path/foo" again, but in French for example
  3. Try to translate the node 'A' with the same alias

Expected result

"/path/foo" already exists in French, so it should be uniquified.

Actual result

The error "The alias "/path/foo" is already in use in this language" is thrown.

Issue fork pathauto-3267989

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

YahyaAlHamad created an issue. See original summary.

yahyaalhamad’s picture

Status: Active » Needs review
StatusFileSize
new972 bytes

One way to fix it is to uniquify the alias before passing it to the validation function.

berdir’s picture

That doesn't make sense to me.

Either you use a generated path, then no validation should be done because the displayed path is purely informal and has no meaning. Or you don't, but then it's not something that is related to pathauto? Are you sure that you are not using and core patches related to alias language handling/fallback?

yahyaalhamad’s picture

@Berdir, yes, no validation should be done when it is auto-generated. But when translating an entity, the alias is assumed to be filled (auto-generated or not), which triggers the validation in PathWidget.php line 86

berdir’s picture

alias lookup in core is language specific, I've never seen that validation error. Again, are you sure you're not using any patches to store aliases as langauge neutral or doing language fallback? are you using the language_hierarchy module for example?

yahyaalhamad’s picture

StatusFileSize
new839.36 KB

@Berdir, It happens on clean Drupal installation.

yahyaalhamad’s picture

But, I think my patch is not optimal since it completely omits the message, it makes sense to throw the message if the path was entered manually. This will make sure to throw the error if the path was entered manually, although, I'm not sure if it is right to do it this way.

yahyaalhamad’s picture

I forgot to mention for this to happen, there should be a URL pattern for multiple bundles.

Ignore this.

yahyaalhamad’s picture

Title: "The alias is already in use in this language" should not be thrown at all » "The alias is already in use in this language" should not be thrown when "automatic URL alias" is enabled
Steven.Fister’s picture

Was this issue fixed?

john_b’s picture

Priority: Normal » Major

I am facing the same error on a site where translation has never been enabled. There is a default user alias pattern 'users/[user:name]'. Attempts to edit a node intermittently trigger the error.

john_b’s picture

Priority: Major » Normal

Uninstalled pathauto and I am still getting the error.

The issue seems to arise where there is more than one copy of an alias. cf https://agaric.gitlab.io/raw-notes/notes/2023-09-19-unable-to-create-new...

In my case there were duplicate aliases for some users, and a user with two identical alias records was intermittently locked out of editing. The duplicate aliases were probably generated by pathauto, but I am not sure I have enough detail to open a useful ticket.

EDIT my problem is not pathauto. LastPass browser extension has started auto-filling the alias field on the node edit form for some users. I am going to look at altering the form to prevent this happening. Password managers are not deterministic in deciding which fields to fill, so altering the form is not a realistic solution to prevent incorrect form fills. LastPass extension also creates problems on user edit forms, but auto-filling the alias field is new.

I am guessing my duplicate user aliases were generated during a D7-D8 migration.

mably made their first commit to this issue’s fork.

mably’s picture

I have been able to reproduce the problem locally when translating a content as described in IS.

Looks like an even better solution is to simply disable field validation when pathauto is active.

Updated MR accordingly.

mably’s picture

False "alias already in use" on translation

The Problem

When two nodes in different languages share the same URL alias (which Drupal allows — e.g. /content/test-node for English and /content/test-node for French), adding a translation of one of them triggers a false validation error: "The alias is already in use in this language."

Root cause: The translation form inherits the source node's alias value.
When the parent PathWidget::validateFormElement() runs, it creates a temporary path_alias entity with the inherited alias and the target langcode (fr). The UniquePathAliasConstraint validator then finds the other French node's alias as a conflict (same alias + same langcode + different system path).

This validation is pointless when pathauto's "Generate automatic URL alias" checkbox is checked, because pathauto will regenerate and uniquify the alias during entity save anyway.

The Fix (PathautoWidget.php)

PathautoWidget::validateFormElement() now skips the parent validation entirely when the pathauto checkbox is enabled (!empty($element['pathauto']['#value'])). The inherited alias value is irrelevant since pathauto will replace it on save.

The Test

testTranslationNoFalseAliasConflict() in PathautoLocaleTest.php reproduces the exact scenario:

  1. Creates an English node with alias /content/test-node
  2. Creates a French node with the same alias (allowed cross-language)
  3. Adds a French translation of the English node via the form
  4. Asserts no "already in use" error appears
berdir’s picture

Status: Needs review » Needs work

There are possibly related core bugs once the same alias for a different language has been saved on the same node. found #3179599: The same path alias cannot be set for two languages for that based on the title. Not exactly the same thing though.

It seems correct that the validation is meaningless if the checkbox is on as pathauto should ensure a valid alias.

The test looks a bit fragile to me because at the end it's just a negative assertion. This will still pass if for some reason the wording of that messages changes. It should assert that saving was successful and what alias was generated then.

mably’s picture

@berdir, not sure to understand what should be done here.

Can you be a bit more precise?

berdir’s picture

You should always also have positive assertions (string X exists) and not just negative ones (string X does not exist), because those can easily pass when the string changes. Add an assert for the alias you expect to have and possibly the node save confirmation message.

mably’s picture

Thanks, you're totally right, I'll fix that.

mably’s picture

Status: Needs work » Needs review

Test has been fixed. We should be ready to merge.

mably’s picture

Assigned: Unassigned » berdir
berdir’s picture

Assigned: berdir » Unassigned
Status: Needs review » Reviewed & tested by the community

Fine. FWIW, the fact that core only has UI/form validation for this case and no validation constraint is a core bug that I recently saw discussed somewhere on Slack. It is possible that this will be added in the future and then this will fail again.

  • mably committed ea0c4b62 on 8.x-1.x
    fix: #3267989 "The alias is already in use in this language" should not...
mably’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.