Documentation should explain that you must set image formatter to "thumbnail" to add an image to an item in the enclosure field

Created on 4 July 2023, almost 2 years ago
Updated 16 February 2024, about 1 year ago

Problem/Motivation

The documentation (e.g. README.md) doesn't clearly explain that administrators must choose a specific image formatter in order for a media:image element to be added to the item.

Additionally, in the case that the field isn't configured correctly, there is no feedback - the media:image element is simply not added.

The following code is unable to determine a file name when the field is e.g. configured to show a media element with the "rendered entity" formatter:

function views_rss_core_preprocess_item_enclosure(&$variables) {
  // <snip>

  foreach ($variables['raw']['items'] as $item) {
    $file = FALSE;

    // File fields.
    if (!empty($item['rendered']['#file'])) {
      $file = $item['rendered']['#file'];
    }

    // Image fields.
    elseif (!empty($item['rendered']['#item']->entity)) {
      $file = $item['rendered']['#item']->entity;
    }

    // When an image field is configured to show a media element
    // with the "rendered entity" formatter, the above code does not
    // find the $file name.

Steps to reproduce

Set up an Advanced RSS feed per the instructions.

Add a media image reference field to the View.

Configure the media image reference field's formatter to anything other than "Thumbnail".

Save the field settings.

Under "Format", go to Show > Settings to access "RSS Feed: Row style options".

Expand "Item elements : core" and under "Enclosure", choose the media image field you just added and save.

Preview the View and note that no media:image field is added.

On the View edit screen, edit your media image field settings and change the formatter to "Thumbnail" with an appropriate image style.

Reload the preview and confirm that the media:image field has appeared.

Proposed resolution

Add the following wording to the documentation:


To add an image to your RSS feed items:

- Add a media image reference field to the View
- Configure the media image reference field's formatter to "Thumbnail" and choose an appropriate image style
- Save the field settings
- Under "Format", go to Show > Settings to access "RSS Feed: Row style options"
- Expand "Item elements : core" and under "Enclosure", choose the media image field you just added and save

Additionally, the Enclosure field description could be updated from:

Describes a media object that is attached to the item.

... to perhaps:

Describes a media object that is attached to the item. The formatter for the field containing your image should be set to "Thumbnail".

Hopefully this information helps someone in the future :)

/Al

πŸ“Œ Task
Status

Active

Version

2.0

Component

Documentation

Created by

πŸ‡¬πŸ‡§United Kingdom alexharries

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024