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
- Create a node with a language. Let's assume the language is Japanese.
- Set a path alias if it is not auto-generated.
- Save the node.
- 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.
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | Screenshot from 2025-10-25 17-52-17.png | 65.21 KB | santanu mondal |
| #11 | Screenshot from 2025-10-25 17-52-01.png | 65.32 KB | santanu mondal |
| #11 | Screenshot from 2025-10-25 17-51-43.png | 92.04 KB | santanu mondal |
| #11 | Screenshot from 2025-10-25 17-51-21.png | 99.51 KB | santanu mondal |
| #5 | Screenshot 2025-10-17 at 15.33.15.png | 201.11 KB | ivan616 |
Issue fork pathauto-3536201
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
santanu mondal commentedComment #4
santanu mondal commentedComment #5
ivan616 commentedI 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.
Comment #6
berdirIt'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.
Comment #7
santanu mondal commentedComment #8
santanu mondal commentedComment #9
berdirThis doesn't apply.
Comment #10
santanu mondal commentedComment #11
santanu mondal commentedi 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??
Comment #12
santanu mondal commentedComment #14
mably commentedMR adds
hook_entity_presaveto 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— newupdateAliasLanguage()method:$entity->toUrl('canonical').hook_entity_update->updateEntityAlias()then regenerates a proper uniquified alias (e.g./content/hello-0).src/Hook/PathautoEntityHooks.php— newentityPresave()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.