Problem/Motivation

when you create a node with a language, the path alias is saved with a language code. If you later change the node's language, the path alias's language code isn't updated to match the new language. This can cause the path alias not to show up when editing the node.

Steps to reproduce

  1. Create a node with a language. Let's assume the language is Japanese.
  2. Set a path alias if it is not auto-generated.
  3. Save the node.
  4. Now edit the same node and change only the language (let's assume the new language is French (FR)) of the node and save it.
  5. Now open the node in the edit form. You will see the path alias will be empty.

Proposed resolution

This issue occurs because the path alias's language doesn't update when the node's language is changed. You'll see an entry in the path_alias table with the old language code. To fix this, you need to update the path alias if the parent node's language and the path alias's language don't match.

Issue fork pathauto-3536201

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

vikramsaini1609 created an issue. See original summary.

santanu mondal’s picture

Assigned: Unassigned » santanu mondal

santanu mondal’s picture

Assigned: santanu mondal » Unassigned
Status: Active » Needs review
ivan616’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new201.11 KB

I have tested code from this merge request locally, and it properly re-created the alias for the node's other language alias pattern.
I have enabled the node multi-language option and inserted both translations with the pattern being:

Basic page pattern - basic_page/[node:title]/[node:content-type]/[node:nid]

After deleting one translation and changing the language of the other translation, the alias was also regenerated.
Tested by landing on the page of the node, and it showed the node correctly.

berdir’s picture

Version: 8.x-1.13 » 8.x-1.x-dev
Status: Reviewed & tested by the community » Needs work

It's not clear why this isn't integrated into the existing hook, needs to be converted to OOP or moved to the generator and needs to be generic, not specific to nodes.

Should also be possible to cover this in our existing test coverage.

santanu mondal’s picture

Assigned: Unassigned » santanu mondal
santanu mondal’s picture

Assigned: santanu mondal » Unassigned
Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Needs work

This doesn't apply.

santanu mondal’s picture

Assigned: Unassigned » santanu mondal
santanu mondal’s picture

error
error
error
error

i have edit for the Node and Taxonomy Both but both case the url is normally working after change the language @berdir please could you briefly tell me what is the exact problem so i can solve this??

santanu mondal’s picture

Assigned: santanu mondal » Unassigned
Status: Needs work » Needs review

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

mably’s picture

Assigned: Unassigned » berdir

MR adds hook_entity_presave to update path alias language when an entity's language changes. Implemented as an OOP hook with #[Hook] attribute and #[LegacyHook] backward compatibility.

Changes

src/PathautoGenerator.php — new updateAliasLanguage() method:

  • Skips new entities (no original), unchanged languages, and entities without a canonical link template.
  • Works for any entity type (not node-only) — builds the system path from $entity->toUrl('canonical').
  • Handles alias conflicts: if the alias string already exists in the target language (from a different entity), the old alias is deleted rather than updated. The subsequent hook_entity_update -> updateEntityAlias() then regenerates a proper uniquified alias (e.g. /content/hello-0).

src/Hook/PathautoEntityHooks.php — new entityPresave() method with #[Hook('entity_presave')], delegates to $this->pathautoGenerator->updateAliasLanguage($entity).

pathauto.module#[LegacyHook] delegate for Drupal 10.6 backward compatibility.

Test coverage

Two kernel tests in PathautoKernelTest:

  • testAliasLanguageUpdatedOnEntityLanguageChange — creates an English node, changes it to French, asserts the alias langcode is updated and no English alias remains.
  • testAliasLanguageChangeWithConflict — creates an English node and a French node with the same title (same alias string, different langcode — valid in Drupal). Changes the English node to French. Asserts the French node's alias is untouched, the changed node gets a uniquified alias (/content/hello-0), and no English alias remains.