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

  1. Standard install
  2. Enable content_translation
  3. Enable a second language, A
  4. Enable translation for the "Article" content type.
  5. Create an article node in English
  6. Translate the article, modifying the title
  7. Visit /rss.xml - the title is in English
  8. 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

Issue fork drupal-2816447

Command icon 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

drupalfan2 created an issue. See original summary.

ldavidsp’s picture

Seeing 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.

ldavidsp’s picture

StatusFileSize
new1.53 KB

this initial pacth is working for me.

heddn’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: how_to_get_feed_title-2816447-3.patch, failed testing.

heddn’s picture

That makes more sense. The initial test failure didn't seem at all related to the changes here.

  1. +++ b/core/modules/node/src/Plugin/views/row/Rss.php
    @@ -163,4 +167,32 @@ public function render($row) {
    +    return 'node';
    

    I don't see any way around this. Any other suggestions? It just feels icky to do it this way.

  2. +++ b/core/modules/node/src/Plugin/views/row/Rss.php
    @@ -163,4 +167,32 @@ public function render($row) {
    +    return \Drupal::languageManager();
    

    Let's inject this, rather than use \Drupal

heddn’s picture

I'm also seeing a similar pattern in Comment and Aggregator. Do we need to fix those or open follow-ups?

ldavidsp’s picture

Status: Needs work » Needs review
StatusFileSize
new11.35 KB

for #6.2

ldavidsp’s picture

StatusFileSize
new2.57 KB

interdiff-3-8

Status: Needs review » Needs work

The last submitted patch, 8: how_to_get_feed_title-2816447-8.patch, failed testing.

ldavidsp’s picture

Status: Needs work » Needs review
StatusFileSize
new3.09 KB
heddn’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/node/src/Plugin/views/row/Rss.php
    @@ -40,6 +44,8 @@ class Rss extends RssPluginBase {
    +  protected $language_manager;
    
    @@ -53,9 +59,20 @@ class Rss extends RssPluginBase {
    +  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    ...
    +      $container->get('entity.manager'),
    

    Missing comments on these new variables.

  2. +++ b/core/modules/node/src/Plugin/views/row/Rss.php
    @@ -53,9 +59,20 @@ class Rss extends RssPluginBase {
    +  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager) {
    

    Let's assign $this->entityType in the constructor.

  3. +++ b/core/modules/node/src/Plugin/views/row/Rss.php
    @@ -163,4 +182,32 @@ public function render($row) {
    +    return $this->entity_Type;
    ...
    +    return $this->language_manager;
    

    Let's not mix snake_case and camelCase in the same class. Use camelCase, since that is was is already in use.

ldavidsp’s picture

Status: Needs work » Needs review
StatusFileSize
new3.19 KB
ldavidsp’s picture

StatusFileSize
new3.34 KB

for #13

+++ b/core/modules/node/src/Plugin/views/row/Rss.php
@@ -53,9 +65,21 @@ class Rss extends RssPluginBase {
+    $this->nodeStorage = $entity_manager->getStorage($this->entity_Type);

rename variable to $this->entityType

The last submitted patch, 13: how_to_get_feed_title-2816447-13.patch, failed testing.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

drupalfan2’s picture

Assigned: drupalfan2 » Unassigned
Munavijayalakshmi’s picture

Assigned: Unassigned » Munavijayalakshmi
Issue tags: +Needs reroll
Munavijayalakshmi’s picture

Assigned: Munavijayalakshmi » Unassigned
Issue tags: -Needs reroll
StatusFileSize
new3.32 KB

Rerolled the patch.

lendude’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This fix makes sense. Some quick review comments:

  1. +++ b/core/modules/node/src/Plugin/views/row/Rss.php
    @@ -42,6 +46,16 @@ class Rss extends RssPluginBase {
    +  /**
    +   * Set the entity type
    +   */
    +  protected $entityType;
    

    We already have protected $entityTypeId; for this

  2. +++ b/core/modules/node/src/Plugin/views/row/Rss.php
    @@ -52,10 +66,24 @@ class Rss extends RssPluginBase {
    +    $this->languageManager = $languageManager;
    ...
    +      $container->get('language_manager')
    

    Like 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

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

peter.draucbaher’s picture

StatusFileSize
new3.32 KB

Applied 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();

heddn’s picture

StatusFileSize
new570 bytes

Here's an interdiff.

piggito’s picture

Status: Needs work » Needs review
StatusFileSize
new3.36 KB
new669 bytes

Adding a hasTranslation validation to prevent errors when the listed content isn't translated for the current language.

andypost’s picture

Status: Needs review » Needs work

that needs tests and #20 makes sense about base class

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joseph.olstad’s picture

Thanks 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.

joseph.olstad’s picture

Version: 8.6.x-dev » 8.8.x-dev

Bumping this to 8.8.x

joseph.olstad’s picture

Version: 8.8.x-dev » 8.7.x-dev

ah sorry this is a bug, it should be in the 8.7.x branch.

heddn’s picture

StatusFileSize
new3.55 KB

Re-roll for 8.8, seems to also apply against 8.7.

heddn’s picture

StatusFileSize
new3.61 KB
new606 bytes

Missed a hunk in the re-roll.

joseph.olstad’s picture

to 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

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

joseph.olstad’s picture

We're still using this patch with 8.7.11

jhuhta’s picture

StatusFileSize
new6.16 KB
new7.41 KB

I didn't understand why we used EntityTranslationRenderTrait in the first place, if we weren't really using it, so I took it into use in query() like they do in EntityRow, and then calling getEntityTranslation() in render().

Also, I moved most of the changes to RssPluginBase as 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 with create().

Still needs tests.

joseph.olstad’s picture

Status: Needs work » Needs review
dire’s picture

#36 applied and works well with 8.8.5. Fixed a problem of not getting translated title and link.

lendude’s picture

Version: 8.8.x-dev » 9.0.x-dev
Status: Needs review » Needs work
Issue tags: -Feeds, -translation

Nitpicks. Needs work mostly for adding tests

  1. --- a/core/modules/node/src/Plugin/views/row/Rss.php
    +++ b/core/modules/node/src/Plugin/views/row/Rss.php
    
    @@ -43,22 +42,12 @@ class Rss extends RssPluginBase {
    -  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository = NULL) {
    ...
    +  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    

    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.

  2. +++ b/core/modules/node/src/Plugin/views/row/Rss.php
    @@ -106,6 +95,10 @@ public function render($row) {
    +    $node = $this->getEntityTranslation($node, $row);
    +
    +
    +
    

    Extra newlines are not needed

  3. +++ b/core/modules/views/src/Plugin/views/row/RssPluginBase.php
    @@ -47,8 +65,12 @@
    +  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository = NULL, LanguageManagerInterface $language_manager, EntityRepositoryInterface $entity_repository) {
    

    We need a BC layer for the new added arguments (see something like \Drupal\views\Form\ViewsExposedForm::__construct in de 8.9.x branch)

jhuhta’s picture

StatusFileSize
new6.32 KB

Addressing #39 here. Also, rerolled the patch against 9.0.x-dev.

  1. Ok, let's just use __construct() and add the needed properties to both Rss.php and RssPluginBase.php, right?
  2. Oops, fixed.
  3. Tried to do this. What about the versions, do we need to keep this until D10? Do we need a change record?
deepak goyal’s picture

Status: Needs work » Needs review

Version: 9.0.x-dev » 9.1.x-dev

Drupal 9.0.10 was released on December 3, 2020 and is the final full bugfix release for the Drupal 9.0.x series. Drupal 9.0.x will not receive any further development aside from security fixes. Sites should update to Drupal 9.1.0 to continue receiving regular bugfixes.

Drupal-9-only bug reports should be targeted for the 9.1.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.2.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jurgenhaas’s picture

Not 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.

fhaeberle’s picture

I agree with that! We tested the patch on v9.1.3 and it applies and works fine.

the.tai.pen@gmail.com’s picture

StatusFileSize
new6.34 KB

Rerolled to core version 9.2.0

Version: 9.1.x-dev » 9.3.x-dev

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Title: How to get feed title in correct language? » Get feed title in correct language
Version: 9.4.x-dev » 9.5.x-dev
Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative

I 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

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new1.66 KB
new8.46 KB
new1.66 KB

- Adding test cases and test only patch.

The last submitted patch, 49: 2816447-49-test-only.patch, failed testing. View results

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests
StatusFileSize
new211.46 KB
new66.46 KB

Tested 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

meeni_dhobale’s picture

Tested the patch #49. Issue is solved after applying the patch. +1 to RTBC.

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

The 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.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kriboogh’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community

Updated 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.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 49: 2816447-49.patch, failed testing. View results

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jurgenhaas’s picture

StatusFileSize
new6.42 KB
new2.53 KB

Re-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.

joseph.olstad’s picture

Status: Needs work » Needs review

If the tests pass, this should be re-marked as RTBC

smustgrave’s picture

Status: Needs review » Needs work

Seems to have some failures.

kriboogh’s picture

Created MR with patch from #58.
Let's see if the tests fail or not.

kriboogh’s picture

Status: Needs work » Needs review

MR with patch from #58 and fixed remaining issues. Please review.

kriboogh’s picture

StatusFileSize
new6.62 KB
new4.46 KB

Added patch and interdiff.

smustgrave’s picture

Status: Needs review » Needs work

Left comments on MR.

kriboogh’s picture

Status: Needs work » Needs review
StatusFileSize
new10.34 KB
new10.07 KB

Fixed remarks.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update +Needs Review Queue Initiative

Feedback appears to be addressed.

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

Thanks 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.

useernamee’s picture

I've tested the MR and it fixes the issue. Once MR comments are addressed it can go into RTBC.

nicrodgers made their first commit to this issue’s fork.

nicrodgers’s picture

rebased the MR to bring it up to date with 11.x

petar_basic’s picture

StatusFileSize
new9.9 KB

Patch for Drupal 11.3

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

jonnyhocks made their first commit to this issue’s fork.

jonnyhocks’s picture

Rebased the open MR to bring it up to date with main

Also fixed some code analysis flags that were highlighted in the pipeline - happy to be guided if they are slightly out of scope or not.

nicrodgers’s picture

Assigned: Unassigned » nicrodgers
nicrodgers’s picture

Title: Get feed title in correct language » Get RSS feed title & comments in correct language
Assigned: nicrodgers » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs change record

I've spent some time on this today and think I've addressed the outstanding issues:

  • In #7 @heddn raised the point that the same pattern/bug exists in comment and aggregator. No subsequent comments addressed that, so I've taken a look and fixed the comment bug here. Aggregator is no longer part of core so we don't have to deal with it here.
  • Drafted a change record at https://www.drupal.org/node/3618490
  • Addressed the deprecation comments on the MR by updating the versions to 12 and 13 respectively; the wording now matches the core policy and links to the newly created change record
  • Fixed testFeedTranslation() which was passing but not actually testing anything useful because it was 404ing and not getting detected.
  • Removed the unrelated formatting changes to buildOptionsForm_summary_options() noted in a previous code review
  • Removed the disused .phpstan-baseline.php entries that were causing the phpstan pipeline job to fail
  • Reverted the unrelated calculateDependencies() try/catch back to the plain load() call (unrelated scope creep flagged in previous code review)

Setting to Needs Review.

smustgrave’s picture

Status: Needs review » Needs work

Can deprecations be updated for 12.1 and removed/fixed in 13 please.