Problem/Motivation
This is a bit of a complex bug I'm encountering. It involves 3 core modules and optionally 1 contrib (pathauto), but I think content moderation may be at the heart of it because I can't seem to reproduce it with non-moderated entities.
The problem is that a translation of an entity cannot be saved if the path alias differs from the published original language version.
To reproduce:
1) Create a node type.
2) Add a moderation workflow to it.
3) Add another language to your site.
4) Enable content translations on that node.
5) Add a pathauto pattern to the node that contains the title.
6) Create an English version of the node.
7) Publish the node through the workflow.
8) Add a translation of that node. Change the title.
9) Save the node (as a draft or other unpublished state - I'm not sure why you can save it once but not a second time).
10) Edit the node again and try to save again (as a draft or other unpublished state).
Form error: "You can only change the URL alias for the published version of this content."
My initial thought was that Pathauto was to blame but after looking in PathAliasConstraintValidator.php I feel like there needs to be some additional logic for translations, moderation, etc. I think (not know) that Pathauto is just exposing this issue because it's changing the alias.
Proposed resolution
TODO
Remaining tasks
Investigate further.
| Comment | File | Size | Author |
|---|---|---|---|
| #34 | empty-alias-check-2930599-44.patch | 1004 bytes | vurt |
| #19 | empty-alias-check-2930599.patch | 1.19 KB | binyc01 |
| #15 | content_moderation-path_alias-2930599-15.patch | 1.08 KB | kcolaers |
Comments
Comment #2
timmillwoodThis is because if you change the title, pathauto will change the path alias. Path aliases are not revisionable therefore cannot be changed in an unpublished revision when there's already a published revision.
Rather than just closing with a "works as designed" comment I thought it'd be best if we add a test to this issue to show the issue. I think the translations brings an interesting element which I don't think is currently tested in core.
Comment #3
mstef commentedThanks for the explanation. So then this is most likely an issue with Pathauto?
Comment #4
mstef commentedComment #5
mstef commentedYou know way more than I do about this, but I'm still thinking this may be a core issue. When the error is thrown Pathauto's PathautoGenerator::updateEntityAlias() is not even called yet. It only is when the first draft of the translation is created -- which works. There is no error on the first save and the path is created and saved. It's the second save where the error is thrown.
Comment #6
mstef commentedPathAliasConstraintValidator::validate() is loading the "original" node via:
but it's never translated.
In my scenario, looking at $original, it's the English version whereas the French version is being saved.
Comment #7
mstef commentedThis is sloppy but this does seem to resolve it:
Comment #8
sylus commentedAs the fix is related to pathauto should I create a patch for that over in other issue? Ran into this issue as well but the suggestion did fix problem for me.Nevermind didn't realize was actually patching the path module, patch forthcoming.
Comment #9
sylus commentedComment #10
sylus commentedComment #11
mathiasgmeiner commentedThe patch from #9 is working fine, thanks!
Comment #12
timmillwood@sylus nice find! I guess this still needs tests though ;)
Comment #14
gábor hojtsyHm, are there any other places where this kind of logic would appear?
Also getTranslation() may throw an \InvalidArgumentException if the translation did not exist, is that not the case if a new translation is just being added and not yet in storage?
Comment #15
kcolaers commentedAn \InvalidArgumentException is indeed thrown in some cases. We could reproduce this by adding a translation (but not yet saving it) for a node with an entity reference, then removing the reference in this translation.
Attached patch to check if the translation exists.
Comment #16
matoeil commentedHi there,
the same form error happens using path module.
Tell me if i am wrong, It means to me it is not possible to have a drupal multilingual site with moderation activated and url rewriting.
EDIT: my previous comment should be reconsidered as i cannot reproduce the problem anymore.
so far so good
Comment #17
porchlight commentedI was running into the issue brought up by comment #14 where the translation had not been created yet, so it was never getting inside the if statement, and never getting the translation, but also when trying to save my translated draft the url alias field was empty, while the english field was not, so checking the $value->alias again the $original->path->alias was always return the constraint validation since it was empty compared to the english alias. This sloppy code seems to get around that.
Comment #18
binyc01 commentedAfter applying patch from #15, I ran into a similar issue as #17. I can save the first draft of a translated content, but get the validation error when saving the same draft a second time.
So in addition to the #15 patch, I added a check for an empty alias:
Comment #19
binyc01 commentedAdded empty alias check to #15 patch.
Comment #20
yang_yi_cn commentedI looked at the code logic in #17 and #19 and I think they are both sloppy.
The logic should be:
- English and French translations should be able to have different path.
- When editing new revision of the content in the same language, you cannot change path alias in draft mode, unless you publish it, then you can change path.
I think the pseudo logic should be like this:
Comment #21
porchlight commentedConfirmed my patch in #17 does NOT work. It allows me to save the node, but it seems to unpublish the original language.
Comment #22
porchlight commentedNever mind... it does work, but I like #19 better.
Comment #23
timmillwoodWe're still waiting on tests.
Comment #24
sylvain lavielle commented#19 patch fixed the problem for me !
Thanks
Comment #25
anish.a commentedIt doesn't fix the problem.
Installed relevant modules - pathauto
My test case is as below.
It shows "You can only change the URL alias for the published version of this content."
I applied patch #19
Comment #26
olivier.br commented#19 solved the issue for me on 8.6.x-dev with content moderation and pathauto.
I was unable to save a new draft revision of a published translation of a node.
Even without changing the path alias.
Comment #27
andreyjan commented#1 works for me when the latest version of pathauto module is installed.
Comment #29
huzookaTest-only patch added.
Comment #31
huzookaComplete test, mainly based on #19.
Comment #32
huzookaHiding my patches since I was fixing an another issue and restoring the previous status :)
Based on the issue's title and summary, this is a 'works like designed' issue or a feature request.
Since path aliases don't have status (right now), if core would allow to change the path alias when creating a new draft, then it would be published immediately
What I fixed: #3001124: Unable to create new draft for content translation even if the path alias does not change
Comment #33
berdirCommented on the other issue first, but after seeing this, I don't think we need to split this.
Yes, this issue title is unspecific but we can improve that, the issue summary shows that it is about the second save, just like your issue. This one also involves pathauto, which does cause a slightly different problem, but if we do the fix that I proposed over there (only compare the alias if we have a matching translation), then I believe it would also kinda work with pathauto even though we could still improve it.
Comment #34
vurt commentedI still had the issue with the current core 8.6.4.
I rerolled the patch from #19 to work with this version.
Comment #35
berdirI don't see how that could fix anything, the code below already checks for having a translation and goes further than this patch used to, by not validating at all if a new translation is added.
Please provide steps to reproduce if you still have a problem and what exactly you expect to happen.
With the other issue being fixed, this is IMHO a duplicate now.
Comment #36
vurt commentedYou're right Berdir: After clearing caches saving worked without the patch.
Sorry for the confusion && thanks
Comment #37
berdirThanks for reporting back, I'm closing this as a duplicate then. I think there shouldn't have been two issues initially.