Problem/Motivation
In Drupal 8.2 I have rss default feeds on front page and feeds on my views. On the bottom of the pages I can click on the feed icon to open the feed page.
On the feed pages the feed titles are not in the correct language. The feed titles appear always in the language the node was created. And the feed title links to the wrong language.
But I need the correct language for the feed title when switching to another language on my drupal site (/en/..., /fr/...., /de/....) and a correct link.
How can I repair this problem in Drupal 8.2?
Steps to reproduce
- Standard install
- Enable content_translation
- Enable a second language, A
- Enable translation for the "Article" content type.
- Create an article node in English
- Translate the article, modifying the title
- Visit /rss.xml - the title is in English
- Visit /A/rss.xml - the title is still in English, we expect it to be in the second language
Proposed resolution
Make sure when visiting the site in the second language that the RSS feed is showing the translated content. So rendering the item should use the translation of the loaded entity (node).
Remaining tasks
Review
Commit
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #51 | after_patch.png | 66.46 KB | smustgrave |
| #51 | before_patch.png | 211.46 KB | smustgrave |
| #49 | interdiff-2816447-45-49.txt | 1.66 KB | mohit_aghera |
| #49 | 2816447-49.patch | 8.46 KB | mohit_aghera |
| #49 | 2816447-49-test-only.patch | 1.66 KB | mohit_aghera |
Issue fork drupal-2816447
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
ldavidsp commentedSeeing the same thing. It is because row/Rss->render() calls entity->link() and entity->label, without designating any language code. This default to defaultLangcode,which was the language code selected when creating the node. Not the language code provided in the URL (or whatever you are using to designate the URL on the views rss page.
Comment #3
ldavidsp commentedthis initial pacth is working for me.
Comment #4
heddnComment #6
heddnThat makes more sense. The initial test failure didn't seem at all related to the changes here.
I don't see any way around this. Any other suggestions? It just feels icky to do it this way.
Let's inject this, rather than use \Drupal
Comment #7
heddnI'm also seeing a similar pattern in Comment and Aggregator. Do we need to fix those or open follow-ups?
Comment #8
ldavidsp commentedfor #6.2
Comment #9
ldavidsp commentedinterdiff-3-8
Comment #11
ldavidsp commentedComment #12
heddnMissing comments on these new variables.
Let's assign $this->entityType in the constructor.
Let's not mix snake_case and camelCase in the same class. Use camelCase, since that is was is already in use.
Comment #13
ldavidsp commentedComment #14
ldavidsp commentedfor #13
rename variable to $this->entityType
Comment #17
drupalfan2 commentedComment #18
Munavijayalakshmi commentedComment #19
Munavijayalakshmi commentedRerolled the patch.
Comment #20
lendudeThis fix makes sense. Some quick review comments:
We already have
protected $entityTypeId;for thisLike heddn said in #7, wouldn't we run into similar problems for other entities? So wouldn't this be better added to the base class?
And most importantly, this still needs test
Comment #22
peter.draucbaher commentedApplied the patch #19 but the language of the title was still in English.
I found that the reason was that the current language was not selected correctly. It should be like
$render_langcode = $this->languageManager->getCurrentLanguage()->getId();Comment #23
heddnHere's an interdiff.
Comment #24
piggito commentedAdding a
hasTranslationvalidation to prevent errors when the listed content isn't translated for the current language.Comment #25
andypostthat needs tests and #20 makes sense about base class
Comment #28
joseph.olstadThanks for the patch @piggito . It is still needed.
I am testing patch 24.
Patch 24 works to bring the title into the correct language in my view
and also brings the other fields into the correct language in my view
However I have a date field and that one stays in the default locale and default language even when viewing the rss in another language.
curiously.
Comment #29
joseph.olstadBumping this to 8.8.x
Comment #30
joseph.olstadah sorry this is a bug, it should be in the 8.7.x branch.
Comment #31
heddnRe-roll for 8.8, seems to also apply against 8.7.
Comment #32
heddnMissed a hunk in the re-roll.
Comment #33
joseph.olstadto get the correct link for other language in an rss feed I also needed another patch:
#2877994-88: Entity Links fields does not have translation support
Comment #35
joseph.olstadWe're still using this patch with 8.7.11
Comment #36
jhuhta commentedI didn't understand why we used
EntityTranslationRenderTraitin the first place, if we weren't really using it, so I took it into use inquery()like they do inEntityRow, and then callinggetEntityTranslation()inrender().Also, I moved most of the changes to
RssPluginBaseas suggested in #20 and #25. In order not to replicate the base class constructor changes in Rss.php, I removed the constructor and replaced the functionality withcreate().Still needs tests.
Comment #37
joseph.olstadComment #38
dire commented#36 applied and works well with 8.8.5. Fixed a problem of not getting translated title and link.
Comment #39
lendudeNitpicks. Needs work mostly for adding tests
If we use create then either nodeStorage needs to be public or we need a setter for it, otherwise this isn't settable in Unit tests. So not sure about this, I would just stick with using __construct(). The pattern of using create always feels more like a contrib solution to me.
Extra newlines are not needed
We need a BC layer for the new added arguments (see something like \Drupal\views\Form\ViewsExposedForm::__construct in de 8.9.x branch)
Comment #40
jhuhta commentedAddressing #39 here. Also, rerolled the patch against 9.0.x-dev.
Comment #41
deepak goyal commentedComment #43
jurgenhaasNot sure I'm allowed to set this to RTBC, but I can confirm (a) it does work and (b) patch #40 addresses all the remaining issue mentioned so far.
Comment #44
fhaeberleI agree with that! We tested the patch on v9.1.3 and it applies and works fine.
Comment #45
the.tai.pen@gmail.com commentedRerolled to core version 9.2.0
Comment #48
quietone commentedI tested this on Drupal 9.5, standard install, using the steps in the IS. I reproduced the problem and then applied the patch and the problem was fixed. Moving to 9.5 since that is what I used for testing.
This still needs a test
Comment #49
mohit_aghera commented- Adding test cases and test only patch.
Comment #51
smustgrave commentedTested the patch #49. Thank you for the clear testing steps in the description.
Confirmed I saw the issue without the patch
Confirmed the issue was resolved with the patch
Comment #52
meeni_dhobale commentedTested the patch #49. Issue is solved after applying the patch. +1 to RTBC.
Comment #53
quietone commentedThe issue summary is incomplete. There is no proposed resolution so how can a reviewer know that the desired fix has been made. Tagging for an Issue summary update.
Changes to the patch were requested for in #39 and there has not been a review of the patch since then, nor has the new test been reviewed.
Based on the above, setting to NW.
Comment #55
kriboogh commentedUpdated the summary proposed resolution.
Since #39, several people have tested the patches. #49 also has been verified. So I propose we set this back to RTBC, so this issue can be closed finally.
Comment #58
jurgenhaasRe-rolled #49 by removing the first code block which is completely unrelated and got removed from core by #3162827: Do not instantiate entity storages in constructors of services that do not always need them - this should not be brought back and isn't required for this issue either. I guess this got in accidentally.
Comment #59
joseph.olstadIf the tests pass, this should be re-marked as RTBC
Comment #60
smustgrave commentedSeems to have some failures.
Comment #62
kriboogh commentedCreated MR with patch from #58.
Let's see if the tests fail or not.
Comment #63
kriboogh commentedMR with patch from #58 and fixed remaining issues. Please review.
Comment #64
kriboogh commentedAdded patch and interdiff.
Comment #65
smustgrave commentedLeft comments on MR.
Comment #66
kriboogh commentedFixed remarks.
Comment #67
smustgrave commentedFeedback appears to be addressed.
Comment #68
quietone commentedThanks for fixing this issue.
@kriboogh, can you comment in the issue the reasoning for the changes you make? Sometime to commit message is enough to provide a clue, but here the message is always the same. It does help reviewer to know what it being done and why.
I left comments in the MR that need attention. This is adding deprecations so there should be a change record and the URL for that change record is to be in the deprecation message. And 10.4 is a maintenance minor so I think this will be deprecated in 11.1.
Comment #69
useernamee commentedI've tested the MR and it fixes the issue. Once MR comments are addressed it can go into RTBC.
Comment #71
nicrodgersrebased the MR to bring it up to date with 11.x
Comment #72
petar_basic commentedPatch for Drupal 11.3
Comment #75
jonnyhocks commentedRebased the open MR to bring it up to date with
mainAlso fixed some code analysis flags that were highlighted in the pipeline - happy to be guided if they are slightly out of scope or not.
Comment #76
nicrodgersComment #77
nicrodgersI've spent some time on this today and think I've addressed the outstanding issues:
Setting to Needs Review.
Comment #78
smustgrave commentedCan deprecations be updated for 12.1 and removed/fixed in 13 please.