Needs work
Project:
Drupal core
Version:
main
Component:
image system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
4 Jan 2021 at 14:54 UTC
Updated:
8 Aug 2024 at 02:20 UTC
Jump to comment: Most recent
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',
],
];
}
Cast the attributes to an array in template_preprocess_image_formatter.
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
matthijsComment #4
matthijsComment #9
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
This will need a test case to show the issue and that it's been resolved please
Thanks!
Comment #11
acbramley commentedThis popped up as part of BSI.
It needs a reroll on to an MR as well as the above mentioned tests.
We could also just NULL coallesce instead of casting to an array.
Comment #12
kim.pepperFrom what I can see, casting to an array would produce an error trying to convert a string or NULL to an array?
Perhaps we could do something like
is_array($var) ? $var : [$var]?This needs a test to verify we aren't breaking anything.