Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 297754

template_preprocess_image_formatter() doesn't respect signature of image theme function

$
0
0

Problem/Motivation

The image theme function requires an array for the attributes variable:

'image' => [
      'variables' => ['uri' => NULL, 'width' => NULL, 'height' => NULL, 'alt' => '', 'title' => NULL, 'attributes' => [], 'sizes' => NULL, 'srcset' => [], 'style_name' => NULL],
    ],

But template_preprocess_image_formatter uses its item attributes for the image render array:

function template_preprocess_image_formatter(&$variables) {
  //...
  $variables['image']['#attributes'] = $variables['item_attributes'];
  //...
}

According to the theme definition these can be NULL, which is not valid:

function image_theme() {
  return [
    //...
    'image_formatter' => [
      'variables' => ['item' => NULL, 'item_attributes' => NULL, 'url' => NULL, 'image_style' => NULL],
      'file' => 'image.field.inc',
    ],
  ];
}

Proposed resolution

Cast the attributes to an array in template_preprocess_image_formatter.


Viewing all articles
Browse latest Browse all 297754

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>