Problem/Motivation
If you don't want to translate your URL alias, the original URL alias won't work with your translations.
Steps to reproduce:
Per #171
1. Enable content translation and language detection based on URL and add the Spanish language.
2. Enable all the article translation options except URL.
3. Enable Pathauto with the default path for articles.
4. Create an English article with the title of Hello and the automatic path of example.com/hello
5. Translate the English article to Spanish with a title of Hola. Do not change the path.
The Spanish article should have a path of example.com/es/hello
In fact, the Spanish article will have a path of example.com/es/hola thus translating the path even though URL is supposed to be untranslated.
to work around this, the editor can manually set the url on the spanish translation back to /hello thus setting the URL back to example.com/es/hello. But, if the automatic URL is used, the url is translated based on the spanish title rather than using the untranslated english path.
Also, before an article is translated, untranslated nodes loaded in Spanish can get a path example.com/es/node/1 instead of example.com/es/hello
Current outcome:
In the alias list (/admin/config/search/path), you have (/my-alias, EN).
Going to /es/my-alias gives a 404.
Expected outcome:
In the alias list, you should have (/my-alias, UND).
Going to /es/my-alias gives a 200 and displays the Spanish translation.
Proposed resolution
- If the entity OR the path field are not translatable, save the path alias with the langcode 'und'.
- If the entity AND the path field are translatable, save the path alias with the langcode of the entity (or translation).
Remaining tasks
- Agree on proposed resolution
- Review
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#188 | 2689459-188.patch | 22.1 KB | vistree |
#161 | 2689459-161.patch | 21.59 KB | ion.macaria |
| |||
#147 | interdiff_145-147.txt | 717 bytes | postyly |
#147 | 2689459-147.patch | 21.61 KB | postyly |
#145 | interdiff-127-145.txt | 5.84 KB | charginghawk |
Issue fork drupal-2689459
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
penyaskitoComment #3
maxocub CreditAttribution: maxocub commentedI was able to reproduce.
We could also set the URL alias language as 'none' instead of 'English' if it's not translatable. If you set it to 'none' in the UI, then the alias works in the two languages.
Comment #4
maxocub CreditAttribution: maxocub commentedI tried this:
It works when adding a new translation, but if we update the original path alias, the one in the second language isn't updated.
Comment #5
maxocub CreditAttribution: maxocub commentedIs that a good start?
Comment #7
maxocub CreditAttribution: maxocub commentedLet's give it another try.
Comment #8
maxocub CreditAttribution: maxocub commentedNitpicking
Comment #9
heykarthikwithuupdated the patch with changes,
Comment #12
anthony.bouch CreditAttribution: anthony.bouch as a volunteer commentedJust ran into the exact same problem, and the code in your patch rescued us. In our case we've implemented this as a module so that we don't have to patch core.
Also in the latest patch 2689459-9.patch - I think you'll need to guard against translation deletions - since hook_entity_update() is called then, but the EntityInterface $entity won't have a path on it.
Something like this....
Comment #13
anthony.bouch CreditAttribution: anthony.bouch as a volunteer commentedAlso not exactly sure why this was necessary, but while deleting a translation removed the url alias from url_alias table, if you delete the source entity (default language), the url aliases are not removed. I had implement hook_entity_delete() as...
Comment #14
anthony.bouch CreditAttribution: anthony.bouch as a volunteer commentedI may be miles off, but there's a bit more to this than meets the eye.
Here's the approach I've taken - https://gist.github.com/58bits/81125d4dcbc646c4a1f8
I'm not sure that content_translation_entity_translation_insert is required, because entity update is called on any translation insert.
I also wrestled to discover the rules for when a path object will have language, source, and alias elements populated and if not, build the source and alias variables manually.
Deletions also need to be taken into account.
In this end, this is a 'brute force' approach. It simply guarantees that the source / default language alias will be used for all available languages, whether or not an actual translation has been created (and given that URL Aliases will be configured as non-translatable' - under Administration > Configuration > Regional and language)
Hope this helps....
Comment #15
maxocub CreditAttribution: maxocub commented@blue_waters: Thanks for your help! About the deletion of the alias not happening when we delete the source entity, there's already an issue for that: #2539634: PathItem::delete() never runs because the path field type is a computed field in disguise
Comment #16
anthony.bouch CreditAttribution: anthony.bouch as a volunteer commented@maxocub - thanks for the issue link.
Comment #17
maxocub CreditAttribution: maxocub commentedDoes someone know if it would be possible (and preferable) to write a test for this using KernelTestBase? Or should WebTestBase be used?
Comment #18
Gábor HojtsyLooking at the patch it should be possible to write tests for the patch with a KernelTestBase if all the services used exist as stubs, but there are definitely several.
Comment #20
smithworx CreditAttribution: smithworx at Lingotek commentedWe've been working on this issue (at DrupalCon New Orleans) and believe that when the path alias is set to not be translatable that we should consolidate all translations to use the same path by setting the langcode to a language code that represents ALL languages (e.g., LANGCODE_NOT_SPECIFIED, LANGCODE_NOT_APPLICABLE).
When we have set the code to LANGCODE_NOT_SPECIFIED the view display of the entity works as expected for all languages. However, the edit entity page shows the path as being blank as it is looking up the path for the specific language (e.g., English, French) rather than a code representing ALL languages.
Comment #21
maxocub CreditAttribution: maxocub commentedFollowing the discussion with @smithworx & @tstoeckler at DrupalCon, here's a new patch with a different approach:
I will try to update the issue summary soon and add some tests, but first I want to see it breaks any tests, and maybe get some feedback.
Comment #22
pp CreditAttribution: pp commentedI tested it with steps in issues description. The patch works fine, but I think tests are needed. Put it back Needs Work.
Comment #23
maxocub CreditAttribution: maxocub commentedHere's some tests!
Comment #25
maxocub CreditAttribution: maxocub commentedComment #26
Kristen PolGreat work! Some nitpicks:
Needs doc block?
URL detection and selection is enabled by default so I don't understand this part.
testAliasTranslatableNode and testAliasUntranslatablePath are almost the same so a helper function could be used if that makes sense. If so, the differences are:
Comment #27
vasi CreditAttribution: vasi at Evolving Web commentedI'm not 100% sure, but I think this is a duplicate of https://www.drupal.org/node/2650962
Comment #28
maxocub CreditAttribution: maxocub commentedYes, it is a duplicate. I guess we should close #2650962: Path alias for entities only work for one language when it's selected to not be translatable since here we have a patch and tests.
Comment #29
maxocub CreditAttribution: maxocub commentedHere's an updated patch addressing the comments from #26, thanks @Kristen Pol for the review!
Comment #30
maxocub CreditAttribution: maxocub commented#27: I closed #2650962: Path alias for entities only work for one language when it's selected to not be translatable as a duplicate of this issue.
Comment #31
Kristen PolNice work! Here are some nitpicks:
More than 80 chars.
Should be 2 sentences or reworded.
More than 80 chars.
Should be 2 sentences or reworded.
$french_alias
is set but then not used since$english_alias
is used twice in function.Comment #32
maxocub CreditAttribution: maxocub commentedComment #33
Kristen PolThanks. The changes look good. I have tested the patch using the steps in the issue summary and it works as expected. Here is a screenshot of after translating the node into Spanish.
Marking RTBC.
Comment #34
alexpottI think we going to need a upgrade path for existing sites here. The fix looks good but we need a post update (doesn't need to be a hook_update_N) to ensure that multilingual sites where the path field is not translatable have aliases with a language of UND and not another language.
Comment #35
Kristen PolThanks for the review. What is a "post update" that is not a hook_update_N?
Comment #36
tstoeckler@Kristen Pol:
While
hook_update_N()
update functions are used when database schema or config structure changes, in D8 we have introduced "Post updates" that are used to just update data/values without any schema changes. That way, we can use the complete Drupal API in post update functions which is problematic inhook_update_N()
. See https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension...Comment #37
Kristen PolOh! Thanks for the explanation. :)
Comment #38
maxocub CreditAttribution: maxocub commentedShould we also think of something to do if someone change the translation settings on a site where there's content already? Like if someone decide to translate the path alias on a content type, should we automatically update the langcode of existing path aliases of that content type?
Comment #39
penyaskito@alexpott #34: How can we prevent that those aliases were not created by hand? I'm not sure if we can assume that we want to generate those in every case.
@maxocub: I think that if we update the translatability settings of a patch in a given content entity, we need to ensure that the alias is changed to the original source language of the entity, and that we generate the same alias for any existing translation, so external links still work. The user would then be responsible of translating them if needed and adding redirects if they want to.
Comment #40
maxocub CreditAttribution: maxocub commentedI did some tests with the title field to see how it works when we change it's translability.
If the title field is not translatable, and you create a French translation of an English node, there will be two entries in the databases with the same title value but with different langcodes. The behavior is the same if the title field is translatable. So when the translatability changes, we don't need to update the values, because they are already there. The only thing that changes is the logic to get the value.
I think we should do the same here with the path aliases, that is to duplicate them for each translations even the field is not translatable. In fact, that was penyaskito's original suggestion.
That would take care of translatability changes on a site with content. Still, we will have to find a way to do a post update. But instead of having to change the langcodes of existing aliases, we would only have to add new ones for the translations.
Any thoughts?
Comment #41
Gábor HojtsyBut then you always need to maintain all the copies when creating/changing aliases, when adding a new language, etc?
Comment #42
maxocub CreditAttribution: maxocub commentedYes, that's true. But to be clear, we would only have to maintain all duplicated aliases when we are changing the original. The alias is only duplicated when we translate the original content. So when we add a new language, we don't have to do anything with existing alias.
On the other hand, if we use the 'und' langcode solution, we would have to duplicate the alias for all current translation if we turn the translatability on for the path alias, and change it to 'und' (or add a new alias with 'und') if we turn it off.
You think we should stick with the current 'und' solution?
Comment #43
Gábor HojtsyIf you maintain multiple synced URL aliases in languages, you need to create the new ones when a language is edited and take care of aliases edited on the URL alias admin pages as well as the API. Sounds like sizable overhead :/
Comment #44
maxocub CreditAttribution: maxocub commentedBased on the comments above, here is what I understand is to be done:
Now what about when we change the translatability of the entity type or the path alias field, do we update again the path alias langcode?
Comment #45
Gábor HojtsyThat is the sad part I think, we don't do anything like that now on translatability change, we made sure not to have a batch job on translatability changes if at all possible :/
Comment #46
maxocub CreditAttribution: maxocub commentedI added a hook_post_update_NAME() as requested in #34. It's the first time I do that so I'm not sure it's OK. Comments would be appreciated.
Comment #48
maxocub CreditAttribution: maxocub commentedComment #49
maxocub CreditAttribution: maxocub commentedI think it's worth noting that if this gets in, it will affect how #2539634: PathItem::delete() never runs because the path field type is a computed field in disguise will be resolved, because of the langcode change to 'und',
Comment #50
BerdirInteresting approach to this problem. I like it, but we might need to document the implications somehow better I think. If possible right on the page where you configure translatability. We're trying that for paragraphs in #2760341: Let the user be aware that Paragraphs fields are not supported for translation.
See also #2511968: Path field should fall back to language neutral aliases (also makes this happen for the form widget!) and #2484411: Manual path aliases are not the same as aliases on the node form on single-language sites for related issues.
And last, I assume pathauto would have to respect this as well then. See #2728725: Special characters like tab or spaces in pattern can break alias generation and #2728663: multilanguage usage for related issues there.
Comment #51
BerdirAh, another thing. I'm not sure about the post update function. you assume that everyone wants it to behave like this, but maybe they accidently didn't enable translation for the path field and because it worked for them, never bothered to change that?
Might be safer to leave out the update function or make it a manual step? As proposed in #2511968: Path field should fall back to language neutral aliases (also makes this happen for the form widget!), we might need to make the widget fall back to either version to make it backwards compatible with existing aliases?
Comment #53
Berdir#2511968: Path field should fall back to language neutral aliases (also makes this happen for the form widget!) now contains a patch that falls back to unspecified for the alias language and saves it in the correct language. After that landed, this issue should IMHO be as easy as respecting the translatable setting for the default langcode.
Comment #54
catchI'd leave the update function out - the existing aliases are valid, they're just not how we think they should be, but we don't know if a site is relying on the current behaviour or not. Could always post a drush script that does the same as the update and link from the change record.
Comment #55
Anonymous (not verified) CreditAttribution: Anonymous commentedAfter applying this patch, the URL aliases function for all translated languages and work with path pattern matches - for example: site.com/en-us/somepath. But, after applying this patch the URL alias field on the edit node page is blank unless that node is translated. So, for nodes that are not translated, the URL alias field when you are edited the node is completely blank even though that clean path has been generated and works correctly. Are the paths being stored in a different table that that field is not referencing?
Comment #56
maxocub CreditAttribution: maxocub commentedComment #57
Alex Bukach CreditAttribution: Alex Bukach commentedIt make sense to inherit default value for the alias from the original node, doesn't it?
Comment #60
vprocessor CreditAttribution: vprocessor at Skilld commentedrerolled #48, for 8.3.x
Comment #61
vprocessor CreditAttribution: vprocessor at Skilld commentedrerolled #48, for 8.3.x, updated
Comment #63
ptmkenny CreditAttribution: ptmkenny commentedComment #64
ptmkenny CreditAttribution: ptmkenny commentedReroll for 8.4.x
Comment #65
FlutterStack CreditAttribution: FlutterStack commentedI tried patch from #61 in drupal 8.3.x php 7.0. Expected outcome, Proposed resolution works fine. But on delete of entity url aliases are not getting deleted, In database url_alias table url aliases are created with language code 'und' but delete function passing language code of an entity.
Please try delete-url-alias-of-source-entity.patch along with #61 patch.
Please consider deleting url alias scenario while creating patch to drupal - 8.5.x.
Thank you.
Comment #66
ptmkenny CreditAttribution: ptmkenny commented@suresh kumara: Patches need to be re-rolled against the latest version of core (now 8.5-x), not old versions like 8.3.
Comment #67
FlutterStack CreditAttribution: FlutterStack commentedPlease try delete-url-alias-of-source-entity.patch along with #61 patch.
Comment #68
ptmkenny CreditAttribution: ptmkenny commented@suresh kumara: The patch in #61 is for 8.3. This issue now needs to be fixed in 8.5.x, the current working version, not 8.3, which is no longer being patched.
Comment #70
bgronek CreditAttribution: bgronek commentedBecause this issue causes most real-world partial translation efforts to fail (who isn't using aliased paths?), I propose escalating this issues's priority to Major.
I will work on re-rolling the aforementioned patch for 8.5 in the coming days.
Thanks!
Comment #71
Zulljin CreditAttribution: Zulljin as a volunteer commentedComment #72
r.nabiullin CreditAttribution: r.nabiullin as a volunteer and at Skilld commentedre-roll patch for 8.4.5 and 8.5.x + added changes from #67
Comment #74
r.nabiullin CreditAttribution: r.nabiullin as a volunteer and at Skilld commentedComment #78
Anonymous (not verified) CreditAttribution: Anonymous as a volunteer commentedHi guys.
I don't know if this helps, but this is what I did and fixed my problem.
I made a custom function that creates aliases of the current node for all the installed languages on node save.
I hope it helps someone.
Please let me know your thoughts.
Comment #79
mqannehre-roll patch for latest 8.6.x
Comment #80
mqannehre-roll patch for latest 8.6.x
Comment #81
zaporylieAs of @Berdir's comment in #53 and by comparing patches in #80 and #2511968-42: Path field should fall back to language neutral aliases (also makes this happen for the form widget!) I mark this issue as postponed by #2511968: Path field should fall back to language neutral aliases (also makes this happen for the form widget!). The scope for both issues overlaps considerably, hence best to get 2511968 done before we continue to work here.
Comment #82
zaporylie#2511968: Path field should fall back to language neutral aliases (also makes this happen for the form widget!) landed. This needs reroll.
Comment #83
savkaviktor16@gmail.com CreditAttribution: savkaviktor16@gmail.com at Skilld commentedRe-rolled
Comment #85
BerdirYeah, I understand what you mean.
> My point here is that right now showing a Path widget when the field is non-translatable is a bug.
And my point is that technically, the field is currently never really non-translatable, because it will always store an alias per translation. So fixing this would be kinda wrong until the other issue happened :)
Comment #86
zaporylie@Berdir, I think you commented on the wrong issue :) #3017157: "Hide non translatable fields on translation forms" option doesn't affect url alias field
But following the thread (which actually more applies more here than there):
> will always store an alias per translation
This is not true. If path is set as non-translatable aliases are created with translation source's langcode. If path field is translatable aliases are created with translation's langcode.
Comment #87
BerdirYeah, indeed, that should be in the other issue.
And good point about the source language, just forget that comment alltogether ;)
Comment #88
zaporylieAn attempt to fix tests.
I also added a test that originates in #3017157-7: "Hide non translatable fields on translation forms" option doesn't affect url alias field (and fails there).
Comment #89
zaporylie...and, for some reason, missing patch file.
Comment #94
zaporylieAn attempt to solve rest-related failures - due to changes in default Path behaviors expected langcode changes from en to und. Tagging "API-First Initiative" to notify people this change may concern.
Comment #96
zaporylieNext chunk of progress.
Comment #99
guaneagler CreditAttribution: guaneagler as a volunteer commentedPatch for language none
Comment #100
guaneagler CreditAttribution: guaneagler as a volunteer commentedComment #101
guaneagler CreditAttribution: guaneagler as a volunteer commentedComment #102
ptmkenny CreditAttribution: ptmkenny commentedComment #103
yogeshmpawarComment #104
yogeshmpawarRe-rolled the patch against 8.8.x branch.
Comment #105
mike.vindicate CreditAttribution: mike.vindicate commentedAdded patch that applies to drupal 8.7.1
Comment #106
charginghawk CreditAttribution: charginghawk as a volunteer commentedRerolling the #105 patch to restore the toUrl work from #3019834: Add @trigger_error() to deprecated url/link EntityInterface methods . Note that patch and #105 are rerolls of the #96 patch. It isn't clear to me what's going on in the #101 patch - it removes the tests and doesn't have an interdiff.
Please remember to add interdiffs, explain the work you're doing, and if you're skipping any other patches, to explain the reasoning there. Thanks!
Comment #107
charginghawk CreditAttribution: charginghawk as a volunteer commentedAnd of course I flub the interdiff.
Comment #109
PasqualleThere is another issue (which this patch does not solve):
If you are on /es/my-alias page, and
{{ url }}
is used in the node twig template, then the url will point to /my-alias. It always links to page without the language prefix. Same problem with entity reference fields.I did not find any issue about it.
Comment #110
charginghawk CreditAttribution: charginghawk as a volunteer commented@Pasquelle That's an unrelated issue, but FYI I noticed it too for some content types that were programatically generated. The url variable is the canonical URL, and under certain circumstances it doesn't correctly use the active language's prefix. The patch on this issue fixed it for me:
https://www.drupal.org/project/drupal/issues/3061761
Comment #111
badrange CreditAttribution: badrange at Digia commentedHere is an attempt to move this issue further, let's see which tests fail. To me it seems like this patch exposes a nice little drupal gotcha: The tests (for example Kernel/PathItemTest.php) are run on a different configuration from what you get when you go to content translation settings and enable article translations.
1. Remove path.post_update.php as requested by Berdir in #51
2. Consistently use LanguageInterface::LANGCODE_NOT_SPECIFIED instead of Language::LANGCODE_NOT_SPECIFIED
3. Add some pieces of code from guaneagler's patch in #101
4. Resolve some deprecation notices added by this patch
Remaining: I think it is wise to add some tests where we set the entity and/or path fields as translatable to match the presumably most common use case. I just want to get some feedback from the community before I spend more time on this.
I thought this was going to be easy to fix the test failures in this patch, instead my beard has grown several new gray hairs.
Comment #112
badrange CreditAttribution: badrange at Digia commentedCode standard fixes before anybody starts nitpicking. Nitpicks are welcome!
Comment #113
johnpicozziCan confirm I was having this issue with Drupal 8.7.7 and the patch in #112 resolved the issue. RTBC +1
Comment #115
gloomcheng CreditAttribution: gloomcheng commentedPatch #112 could work on Drupal 8.7.8 and really resolved the issue. RTBC + 1
Comment #116
badrange CreditAttribution: badrange at Digia commentedSetting RTBC due to two comments confirming that #112 works
Comment #117
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe patch needs to be rerolled for all the recent path alias improvements from Drupal 8.8.
Comment #118
alexpottThis probably should be discovered if it is true or not before commit.
This looks like this can be simplified if the $conditions assignment took place last.
In the case where you have aliases created with a langcode but now they'd be created with UND. Also isn't the behaviour going to change for new aliases on the site so a site over time will get in an interesting situation? I'd be happy to be wrong about all this.
Comment #119
Piotr PakulskiTrying to roll to 8.8.1
Comment #120
Piotr PakulskiNext round of the rerolling, trying to pass the tests.
Comment #121
Piotr PakulskiReroll, trying to pass the tests. This time disabling the patch for workspace module since 8.8.1 there is new PathWorkspacesTest which I can no longer work on to pass it. My scenario does not need to use workspaces. Keep this in mind while using this version of the patch.
Comment #122
Piotr PakulskiComment #123
Piotr PakulskiComment #124
Piotr PakulskiComment #125
rrrob CreditAttribution: rrrob at Chapter Three commentedClean up computeValue.
Comment #126
Krzysztof DomańskiAdded interdiff.
Comment #127
Krzysztof DomańskiI modified it.
Comment #128
ultrabob CreditAttribution: ultrabob commentedI looked at the code, and applied #127 to 8.8.1. It applied fine, and fixed the issue I had, in which the initial url alias I set on a node would be language specific, and any translations created would have no alias created. Now the first node gets LANGCODE_NOT_SPECIFIED, which means the translation works as expected. I don't really know enough about the inner workings of the code to review that part, but the patch works for my issue.
Comment #129
ultrabob CreditAttribution: ultrabob at Kalamuna commentedFollowing on from the testing above, I found what seems like it may be unexpected behavior, this is not on a clean install, so it is possible another patch or something is causing the issue. I'm doing my testing on Basic Page. See the attached screenshot for the translation settings for that content type.
URL Alias is not set as a translatable field, but it shows up on both the initial node creation form and the translation creation form. If I change the URL alias in the translation, the new translation with LANGCODE_NOT_SPECIFIED replaces the old one. Given the settings shown, I would have expected that the field not show up in the translation form.
Comment #130
jatinkumar1989 CreditAttribution: jatinkumar1989 commentedHI, #127 not working for me.
Let me explain what my issue is:
Have a node (e.g nid 123) in EN whose path is : "/en/abcde"
now if change my language to german "DE" (not having the transalted node, just changed the path in browser)
node path currently: "/de/node/123"
Expected out :
if Node is not translated:
DE Node URL : "/DE/abcde" (not translated the node, just chnaged the path in browser)
EN Node URL : "/EN/abcde" (orignal Node)
Any help please
Thanks in Advance.
Comment #131
jatinkumar1989 CreditAttribution: jatinkumar1989 commentedComment #133
azinck CreditAttribution: azinck at Forum One commentedI have a question that's related to this, but not identical: can anyone clarify why URL Alias translation is required at all if I don't have the Content Translation module enabled? In 8.9.1, on a completely clean standard install, by merely enabling the Language module (and NOT any other translation modules) the Content Language interface exists, URL alias is checked, and *cannot be un-checked*. See my attached screenshot.
This 1) is baffling and 2) makes the pain points outlined in this thread much more common for people who might not even want to translate content or aliases but still use some localization functionality or just translate the admin interface.
Can anyone shed light on why this behaves this way?
Comment #134
azinck CreditAttribution: azinck at Forum One commentedCan someone clarify what this patch is meant to accomplish right now? I'm not able to see the effect I had hoped to see. After applying this patch I'm still getting aliases created with a langcode set to my site's default language. I'd expected to see them set to und.
Comment #135
azinck CreditAttribution: azinck at Forum One commentedOk, I found what appears to be a workaround for my particular use-case: I have enabled custom language settings for the content entity and set the language to "not specified" for every content type. This seems like it should be the default approach taken by core when no language has been specified, but alas, apparently it is not. By so doing, I'm able to create content with no language specified and the subsequent aliases that are auto-created also have no language specified. I was able to do this without the patches in this thread. I'm still not too clear on what the patches here actually do.
Comment #136
Coufu CreditAttribution: Coufu commentedI originally wanted the same as OP and as described in #130, but ended up going a different route and not using any patches in this issue.
Few notes and learnings:
Comment #137
Kristen PolBased on #136 ("Patches didn't work for me"), moving back to "Needs work".
Comment #139
Giuseppe87 CreditAttribution: Giuseppe87 at Elicos commentedI confirm #127 doesn't apply on 9.1.3, while the workaround explained in #136 is working.
Comment #140
ThirstySix CreditAttribution: ThirstySix as a volunteer and commentedI tried with #136. but it's not working for mine.
Comment #143
charginghawk CreditAttribution: charginghawk as a volunteer commentedRerolling #127, just rejiggering line numbers so patch applies.
Comment #145
charginghawk CreditAttribution: charginghawk as a volunteer commentedThe test fails were due to deprecations, here they're cleaned up.
Comment #146
charginghawk CreditAttribution: charginghawk as a volunteer commentedA lot of the comments since #127 have to do with the intention of the patch, and admittedly the testing steps on the ticket are unclear, so I'm adding more specific steps to describe and reproduce the issue. Reminder that you can use the excellent simplytest.me to spin up an environment and reproduce the issue yourself (and also select the patch to confirm the issue is fixed).
As for the code itself, basically it's just adding `isTranslatable()` checks to path fields (Drupal\path\Plugin\Field\FieldWidget\PathWidget, Drupal\path\Plugin\Field\FieldType\PathItem, Drupal\path\Plugin\Field\FieldType\PathFieldItemList) and if not translatable setting the field's langcode to LANGCODE_NOT_SPECIFIED.
I don't think anyone's addressed the feedback in #118 so that's the next todo.
Comment #147
postyly CreditAttribution: postyly commentedAdded the creation of an alias when adding a translation.
Comment #148
Kristen PolTagging for manual testing based on issue summary steps.
Comment #149
joshua1234511Manually tested the patch provided in #147 with the steps from issue summary.
In the alias list, there is only (/my-test, UND).
Both links work
/my-test
/es/my-test
Can be marked as RTBC, After final patch code review.
Comment #150
Kristen PolI looked through the code and found a couple nitpicks below. Also, since the code for deleting the node has been updated, it might be good to manually test that.
This comment uses
'und'
while the rest of the comments useLANGCODE_NOT_SPECIFIED
.Same as above.
Comment #151
jacktonkin CreditAttribution: jacktonkin at ISSUP commentedPer #146 and #150 this is still needs work for #118.2 and #118.3 (#118.1 has been addressed as the changes to the method are much simpler now and the comment has gone away).
For #118.2 and #118.3, I think the logic for deleting path aliases could be:
So we can just do:
Or is it a problem to delete manually created aliases for translations that don't exist?
Comment #152
jacktonkin CreditAttribution: jacktonkin at ISSUP commented#151 would also fix #3017148: Language neutral url aliases are not deleted when deleting the parent entity.
Comment #153
Kristen PolTagging for bugsmash.
Comment #154
Rob230 CreditAttribution: Rob230 at CTI Digital commentedI tested #147 on Drupal 9.3 and it didn't do anything. I create a new page, it has an English alias. But visiting the URL for the page in the other language is a 404.
Comment #155
proweb.ua CreditAttribution: proweb.ua commented#145 #147 Drupal 9.3.12 and 9.3.x-dev
not works
Comment #157
ksenzeeFWIW #147 works perfectly for me on 9.3.12. We're using subdomains for language detection, with translatable content types and untranslatable URL alias fields. We were forcing URL aliases to language-neutral using hook_path_alias_presave, and any time we added a translation we got a new duplicate path alias set to 'und'. With this patch, we no longer get duplicate aliases.
Comment #159
Greg BoggsPatch #147 does not work for me. I followed the directions as best I could, and when I save "test node" in spanish as "spanish test node", I still get the spanish URL of es/spanish-test-node rather than es/test-node
Comment #160
Greg BoggsIn my case, the reason this did not work as expected is because my path auto alias in Pathauto was set to [node:title].
I set my path auto alias to [node:original:title], and I get this feature with no need for a core patch at all because it's Pathauto generating the translated paths.
Comment #161
ion.macaria CreditAttribution: ion.macaria as a volunteer and commentedRe-roll #147 patch created for 9.5.x.
Comment #162
Greg BoggsIn Drupal 9, with, or without this patch, translated URLs only work if you use an automatically generated URL in English.
If you create an english node, give it a manual URL and then translate the node, the translated node has a url of example.com/node/
Comment #164
jedihe CreditAttribution: jedihe at Council on Foreign Relations commented@Greg Boggs: I could not reproduce the issue you report. Used a clean 9.5.9 install on simplytest.me and tried both Drupal core alone, as well as with pathauto (different instances).
Testing results:
Drupal core 9.5.9
Drupal core 9.5.9 + pathauto
Comment #165
Greg BoggsThe goal is to not enable url translation so URLs should be:
Article Title English: Hello
Article Title Spanish: Hola
Article URL English:
example.com/hello
Article URL Spanish:
example.com/es/hello
It sounds like to me you got:
Article Title English: Hello
Article Title Spanish: Hola
Article URL English:
example.com/hello
Article URL Spanish:
example.com/es/hola
Comment #166
Greg BoggsI can get it all to work as long as an editor always manually enters the URL and doesn't use the checkbox. But, as soon as the default automatically generated alias is used, I cannot. Perhaps it's a configuration difference between our test sites.
Comment #167
yash.rode CreditAttribution: yash.rode at Acquia commentedI was trying to reproduce the problem from steps to reproduce, can someone confirm if they can do step 5: Within Article, uncheck the URL alias field for Drupal 11.x? I am not able to do so because once we enable translation for article it gets enabled for all the fields and if we try to save
admin/config/regional/content-language
with URL alias for article unchecked it does not get saved.Comment #168
yash.rode CreditAttribution: yash.rode at Acquia commentedNeed some help with #167
Comment #169
smustgrave CreditAttribution: smustgrave at Mobomo commentedCan the steps be updated please.
Followed them but going to es/my-alias took me to the Spanish translation. So I didn't have the issue.
Comment #170
lauriiiI also cannot reproduce this anymore. I think there's a good chance that this was fixed by #2336597: Convert path aliases to full featured entities (or at least improved). If there's a set of customizations required to trigger this, it would be great if the steps in the issue summary would be updated with those.
Comment #171
Greg BoggsI have not tested this in two months.
Steps to reproduce:
1. Enable content translation and language detection based on URL and add the Spanish language.
2. Enable all the article translation options except URL.
3. Enable Pathauto with the default path for articles.
4. Create an English article with the title of Hello and the automatic path of example.com/hello
5. Translate the English article to Spanish with a title of Hola. Do not change the path.
The Spanish article should have a path of example.com/es/hello
In fact, the Spanish article will have a path of example.com/es/hola thus translating the path even though URL is supposed to be untranslated.
to work around this, the editor can manually set the url on the spanish translation back to /hello thus setting the URL back to example.com/es/hello. But, if the automatic URL is used, the url is translated based on the spanish title rather than using the untranslated english path.
Also, before an article is translated, untranslated nodes loaded in Spanish can get a path example.com/es/node/1 instead of example.com/es/hello
Comment #172
lauriiiI was able to reproduce this with the steps in #171. The key step is to not enable translation for URL alias field when enabling translation for the content type. 👍
Comment #175
narendraRAfter applying patch #161 for 11.x in MR, url alias(admin/config/search/path) with Language None is created.
Comment #176
smustgrave CreditAttribution: smustgrave at Mobomo commentedComment #177
smustgrave CreditAttribution: smustgrave at Mobomo commentedUpdated issue summary after also confirming the issue following steps in 171
Applying the MR does resolve the issue for me.
Comment #178
BerdirSome thoughts on this, I didn't look at everything in depth, but posted a few comments on the test as well, pretty sure that's not quite ready and needs some cleanup, it's obvious that parts of it are very old.
* We need to be careful about existing sites here, as this changes the behavior for them suddenly. Until now, the translation setting on this field didn't really do anything and there are two possible cases to consider here:
** Sites that accidentally have this configured but don't actually want this behavior. There's not much we can do about that, but we should have a change record and probably also a release snippet to tell users to review their alias field translation setting and enable it if they want to have per-language aliases.
** Sites that would like to have this behavior, tried it, are not using this patch but kept it as that. That's fine, it will start to work for them now. We do however need to make sure that existing aliases continue to work. Specifically, that means the alias lookup should be the language or UND, not either or (exclusive OR) the other depending on the setting. Maybe that's already covered in tests, but we should do a manual test as well. Either by creating content first then applying the patch, or changing the translation setting.
* There is a very strange and unfortunate module exists check that was added in #121 and was never talked about again later. Hardcoded module exists checks are really not nice. If it's needed, then other modules might need it too and won't be able to add the same workaround. Or it's not needed and we should instead fix some tests like many other tests were adjusted as well. Can we remove that snippet and see what exactly ails and look into that?
* Not a problem, just a note. There's a similar but different use case of alias fallbacks: #3091336: Allow altering of the language fallback for path aliases. The difference is that you can *optionally* have translated aliases if your content is translated, but if it's not then you want it to fall back to the alias of whatever language does exist. This is typically useful in combination with language fallbacks and regional/sub-languages, where not all content is expected to be translated. I think they are completely parallel and should not interfere, but make sure that your use case isn't actually that issue.
* This feature has also been asked for in the pathauto issue queue and I've pushed back/ignored it for now until core is consistent, now/once this actually happened, pathauto will need to be updated as well to correctly respect this setting as well.
Comment #179
Internetter CreditAttribution: Internetter commentedHi,
we also actually use the patch, but with the module language_neutral_aliases.
We test a lot of variants, but it seems that only the module really works.
With the patch from #161 alone it is not really working. We have
* Languages DE and EN
* Content is translatable, but url alias field is not translatable
* url alias pattern is set for all languages
But in result for new created content the path alias is set in database for DE language only. Not for "UND" (language neutral). So with no translation the path alias won't work with the second language.
If the path alias field is not translatable, the path alias should always be set to langcode UND, what the patch in our case did not do. Should it work like this?
With the module language_neutral_aliases the path aliases would be created as UND-aliases, so you can call it with other languages and get the default language not translated content. And of course the path alias stays always the same. (we use a alias pattern with node:source:title) so it is using always the original language title.
Bye
Martin
Comment #180
BerdirThis issue will only work with manual aliases, not pathauto, that will need to be adressed separately in that module
Comment #181
yash.rode CreditAttribution: yash.rode at Acquia commentedHi, I am bit confused between #171 and #180. #171 says we need to enable pathauto to reproduce this issue and #180 says we shouldn't.
What are the steps to reproduce without using pathauto for this issue, as suggested by @Berdir?
Comment #182
tim.plunkettThe STR include enabling Pathauto, but as @berdir points out in #180, this should be reproducible in vanilla core.
Can someone update the IS to explain how to reproduce this without Pathauto?
Comment #183
Greg Boggsheh, that's my fault. Y'all are correct. I didn't realize drupal core generates aliases without pathauto because I've never seen a Drupal site without Pathauto. After looking at core without Pathauto We'll need a separate ticket in Pathauto for the Pathauto part.
Comment #184
smustgrave CreditAttribution: smustgrave at Mobomo commentedSo are the steps in #171 accurate minus the pathauto module?
Comment #185
smustgrave CreditAttribution: smustgrave at Mobomo commentedTried following #171 without pathauto and the steps aren't super clear. Do we need to manually set the alias now?
Comment #186
Berdir> Do we need to manually set the alias now?
Yes.
Comment #187
DenisVSI have this issue in my D10 site — unable to use language-neutral alias on second+ language.
Which patch do I have to apply?
Comment #188
vistree CreditAttribution: vistree commentedI updated the patch from #161 to work with Drupal 10.2.3. Only one small change within core/modules/jsonapi/tests/src/Functional/NodeTest.php