0

I use Drupal 8.7.11.

I personalized the RSS feed via a function in my theme my_theme_preprocess_views_view_row_rss() in view.inc file.

I added this to add content:encoded tag in RSS feed called google_news.

if ($variables['row']->description['#view_mode'] === 'google_news') {
    $variables['content_encoded'] = \Drupal::service('renderer')->render($node->get('field_mg_paragraph')->view('google_news'));
}

This code adds the content:encoded tag to the RSS feed, but it only works with a few exceptions.

This works the first time you open the RSS feed /feeds/google-news.xml page (directly by URL, without going through the site).

It no longer works when I refresh the page after visiting the home page of the site or a blog post while logged in as administrator / user.

I investigated, and a SESS cookie is placed in my browser, obviously, this cookie is problematic.

enter image description here

Anyone have any feedback on it?

If I am disconnected and that I delete cookies, or that I navigate in private navigation on Google Chrome, I do not have this problem of cookie placed in the browser, and therefore my code works, it adds the content:encoded tag.

  • 1
    It's not the cookie causing your problem - it's more a symptom that suggests that your solution doesn't play nicely with caching. A session cookie being created is perfectly normal behaviour. It may be that the check you are making is not 100% reliable when output is cached, and you may have to use a slightly different approach. – Alfred Armstrong Feb 10 at 16:18
  • Thanks @AlfredArmstrong ! OK, I'll try to have another approach. Obviously, when I empty the Drupal cache via the interface provided for this purpose, the addition of the content: encoded tag is well done, but when I refresh the page of the RSS feed, the tag disappears. It appears only once. An idea? – pirmax Feb 11 at 8:29
  • I have found in the past that the variables passed in to preprocess functions may vary so you probably need to see if there's a more reliable way to get that view mode – Alfred Armstrong Feb 11 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.