| Project: | Drupal core |
| Version: | 8.x-dev |
| Component: | image system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | webchick |
| Status: | closed (fixed) |
| Issue tags: | Notice: Undefined index xxx |
Issue Summary
Notice: Undefined index: path in theme_image_formatter() (line 549 of /home/wiert/www/drupal-7.0/modules/image/image.field.inc).
Solution: in image,field.inc: add !empty() (see below):
function theme_image_formatter($variables) {
$item = $variables['item'];
$image = array(
'path' => $item['uri'],
'alt' => $item['alt'],
);
// Do not output an empty 'title' attribute.
if (drupal_strlen($item['title']) > 0) {
$image['title'] = $item['title'];
}
if ($variables['image_style']) {
$image['style_name'] = $variables['image_style'];
$output = theme('image_style', $image);
}
else {
$output = theme('image', $image);
}
-- if ($variables['path']) {
++ if (!empty($variables['path'])) {
$path = $variables['path']['path'];
$options = $variables['path']['options'];
// When displaying an image inside a link, the html option must be TRUE.
$options['html'] = TRUE;
$output = l($output, $path, $options);
}
return $output;
}
Comments
#1
I'm going to try rolling a patch for this.
#2
Thanks for the solution! Here's a patch. It's untested.
Also, moving this to 8.x because bugs need to be fixed there first.
#3
I'm not sure the suggested fix in the original post is proper. $variables['path'] is assuredly set (since image_theme defines to it be at least NULL).
Are we sure the undefined index 'path' isn't coming on the line below?
#4
x-post!
#5
#6
The last submitted patch, 1124786-fix-notice.patch, failed testing.
#7
previous patch didn't fix the issue as stated in #3.
Attaching new one, valid for both 7.x and 8.x
#8
The last submitted patch, noticefix-1124786.patch, failed testing.
#9
Any updates on this issue?
#10
#7: noticefix-1124786.patch queued for re-testing.
#11
I had this error with Drupal Commerce when I used a product image in a product display view with view field setting "Link image to: Content". When changing that setting to "Link image to: File", an error disappeared. Notice that fields in that view are used in reference to product fields.
#7 fixed an error for me.
Tormi
#12
In the exact situation as #11, haven't tried patch yet.
#13
Tested the patch, code looks good, can't see anything go wrong
#14
Committed to 7.x and 8.x. Thanks.
#15
Automatically closed -- issue fixed for 2 weeks with no activity.
#16
I'm getting this now on a D7 site. I added an image field to the basic page content type, added an image and when previewing, I get this error. The image does not show up at all on the live site.
The errors are (actual website path omitted):
Notice: Undefined index: alt in theme_image_formatter() (line 603 of /site1/modules/image/image.field.inc).
Notice: Undefined index: title in theme_image_formatter() (line 616 of /site1/modules/image/image.field.inc).
Any thoughts?