Problem/Motivation
When viewing a node revision in a non-default language, it still displays in the default language.
To reproduce:
- Create a translated node, with multiple revisions
- Go to the revision history page in a non-default language, eg: /fr/node/1/revisions
- Click one of the revisions displayed. The node displays in the default language, see attached picture.
Proposed resolution
Add getTranslationFromContext() in NodeController::revisionShow().
Remaining tasks
Write patch. Write tests.
User interface changes
Revisions will display in the correct language. Anybody who depends on the old behaviour had odd ideas.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #38 | 2694555-26.patch | 13.19 KB | alexpott |
| #26 | 2694555-26-test-only.patch | 3.66 KB | amateescu |
| #22 | 2694555-22.patch | 13.13 KB | amateescu |
| #22 | 2694555-22-test-only.patch | 3.61 KB | amateescu |
| #18 | interdiff.txt | 10 KB | amateescu |
Comments
Comment #2
vasi commentedHere's a test that demonstrates the problem.
Comment #3
vasi commentedComment #4
vasi commentedAnd here's a fix.
Comment #5
vasi commentedPresent in 8.0 through 8.2, it turns out. Patches still apply to 8.2.
Comment #8
heddnI reviewed the code in question to see what getTranslationFromContext() does. Code looks solid and is doing the right thing. Tests look sufficient.
Without the patch, the behaviour is identical as described in #0. With the patch, the issue is fixed.
Comment #9
dawehnerIMHO we should fix this in
\Drupal\Core\ParamConverter\EntityRevisionParamConverteras well, given that this will be used hopefully in the future for nodes as well.Comment #10
heddnre#9: Is this what you mean?
Comment #11
dawehnerJust that doesn't work, we need to load the revision still ...
Comment #13
therealssj commented@dawehner
Like this?
Comment #14
therealssj commentedComment #16
catchI'm not sure what happens if:
- you have a non-default revision
- you load it
- you change something
- you save it
Do we save the non-changed translated values from the revision we loaded, or the default one?
Bumping to crtical, because if it's the default revision that's a data integrity issue, we can downgrade if it's not.
Comment #17
amateescu commentedHere's a test for the scenario described in #16.
Comment #18
amateescu commentedFixed the unit test fail from #13 by properly injecting the entity repository service and also moved the test method to an existing test class (
\Drupal\node\Tests\NodeTranslationUITest).Since the test-only patch #17 passed, this is not a critical issue anymore.
Comment #19
amateescu commentedForgot a tag :/
Comment #20
dawehnerIt seems to be that we don't really have test coverage for this code change. The unit tests seems to not really cut it. Could we expand the test in EntityRevisionTranslationTest to include something for that as well?
Comment #21
timmillwood@dawehner - Doesn't the test in
NodeTranslationUITestcover this?Comment #22
amateescu commented@timmillwood, nope, that only covers the changes in
\Drupal\node\Controller\NodeController::revisionShow().Here's a test for the changes in
EntityRevisionParamConverter. The test-only patch is also the interdiff.Comment #23
dawehnerThank you @amateescu!
Comment #26
amateescu commentedApparently, entity URLs don't go well with simpletest when running in a subdirectory, let's just use the URL directly like we do everywhere else.
Comment #27
dawehner+1 for this job. I could have seen that. Ideally you set the langcode in the URL object and just pass that to
drupalGet.Comment #28
berdiryou just can't use toString(), you have to use getInternalPath(), then it should work fine. Or you can just pass the Url object to drupalGet(), that should actually work as well (in simpletest, not sure about phpunit ,didn't check what kind of test this is)
Comment #30
webchickSounds like needs work
Comment #31
dawehnerI tried to do that, but I think the test setup is wrong, as it doesn't yet have URL prefixing configured.
Comment #33
amateescu commentedI tried that as well but, unfortunately, it doesn't generate a proper URL for the entity revision in a specific language.
I don't know if that's a bug or just the test setup, so I still think the patch in #26 is good to go.
Comment #34
dawehnerYeah me too, but we could file a follow up for that.
Comment #35
berdirYes, toUrl() doesn't add that option, you would have to to something like setOption('language', ..) yourself on the url object.
We discussed that before. I think it would be nice if it worked like that.
Comment #36
dawehnerI did explictly that in #31 but it still didn't worked.
Comment #37
catchMoving this to 8.1.x since it's a straight bugfix.
Comment #38
alexpottJust uploading the correct patch to be the last patch on the issue.
Comment #39
alexpottComment #40
xjmRegarding #37, it's a straight bugfix, but it does involve a constructor change on a paramconverter to add an additional service. In our BC policy we say:
So we are okay doing this in 8.1.x for that not-an-API-change. I wondered though about whether we need to force a cache rebuild.
Comment #41
alexpottThe version change will be enough to cause a container rebuild so no cache rebuild is necessary.
Committed and pushed 9b07bc544c49296bd4fb76b08d676665d9e2d0c1 to 8.2.x and 97d2695 to 8.1.x. Thanks!