Theme declaration and templates mismatch for feed_icon

Created on 3 July 2023, over 1 year ago
Updated 26 May 2024, 7 months ago

Problem/Motivation

  • The core templates for feed_icon all mention availability of three properties: title, url, and attributes.
  • All three properties are used
  • But when building a render array, #attributes is ignored.

The problem is that drupal_common_theme() declares feed icon as:

    'feed_icon' => [
      'variables' => ['url' => NULL, 'title' => NULL],
    ],

So, without the attributes key. When modifying it like this, #attributes works normally

    'feed_icon' => [
      'variables' => ['url' => NULL, 'title' => NULL, 'attributes' => []],
    ],

Steps to reproduce

  1. In some module, build a render array like:
      $build['feed'] = [
            '#theme' => 'feed_icon',
            '#url' => Url::fromRoute('view.frontpage.feed_1'),
            '#title' => $title,
            '#attributes' => ['title' => 'some title', 'class' => ['some-class']],
          ];
    
  2. Observe how some-class is not added to the resulting class list.
  3. Add , 'attributes' => [] to the feed_icon definition in drupal_common_theme(), retry.
  4. Observe how the class is now correctly set.

This leads to workarounds like 📌 Support use of URL path in hook_preprocess_feed_icon Fixed .

Proposed resolution

Add , 'attributes' => [] to the feed_icon definition in drupal_common_theme().

Remaining tasks

Do it.

User interface changes

Before

After

API changes

None.

Data model changes

None.

Release notes snippet

None.

🐛 Bug report
Status

Fixed

Version

11.0 🔥

Component
Theme 

Last updated 28 minutes ago

Created by

🇫🇷France fgm Paris, France

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024