0

Within the mymodule_preprocess_views_view_row_rss(&$variables) hook, we are able to get the link by using $variables['row']->link. However, we are not able to access the node for which that link is for.

How can we use the value returned from $variables['row']->link to get the node?

Goal(s):

  1. Using the link value, get the node so that we can fetch additional fields such as field_image within the hook
  2. Add the field_image as a variable to $variables array so that it can be used in the views-view-row-rss.html.twig file.

We tried with no success.

function mymodule_preprocess_views_view_row_rss(&$variables) {
  $link_value = $variables['row']->link;
  $path = \Drupal::service(`path.alias_manager`)->getPathByAlias($link_value);
  $node = \Drupal\node\Entity\Node::load($path);
  ksm($node); // returns null. 
}

Additional view settings we tried with no success:

Under Fields

  • Added field_image field

Format

  • Format: RSS Feed

Within mymodule_preprocess_views_view_row_rss(&$variables) hook, we tried printing all the variables using ksm($variables) to see if field_image was returned, but it was not.

  • Any reason you’re not adding the data you need to the View as normal? Then it’d already be there, no manual intervention required – Clive Feb 25 at 17:19
  • @Clive I additional some details regarding the view settings. When we tried adding the field_image, it was still not accessible in the hook and twig template. – usernameabc Feb 25 at 17:24

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.