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;
}

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

webchick’s picture

Assigned: Unassigned » webchick

I'm going to try rolling a patch for this.

webchick’s picture

Version: 7.0 » 8.x-dev
Status: Active » Needs review
FileSize
520 bytes

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.

bfroehle’s picture

Version: 8.x-dev » 7.0
Status: Needs review » Active

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?

bfroehle’s picture

Status: Active » Needs review

x-post!

bfroehle’s picture

Version: 7.0 » 8.x-dev

Status: Needs review » Needs work

The last submitted patch, 1124786-fix-notice.patch, failed testing.

zambrey’s picture

Title: Undefined index » Notice: Undefined index: path in theme_image_formatter()
Status: Needs work » Needs review
FileSize
528 bytes

previous patch didn't fix the issue as stated in #3.
Attaching new one, valid for both 7.x and 8.x

Status: Needs review » Needs work

The last submitted patch, noticefix-1124786.patch, failed testing.

djv’s picture

Any updates on this issue?

zambrey’s picture

Status: Needs work » Needs review

#7: noticefix-1124786.patch queued for re-testing.

tormi’s picture

FileSize
55.09 KB

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

carn1x’s picture

In the exact situation as #11, haven't tried patch yet.

attiks’s picture

Status: Needs review » Reviewed & tested by the community

Tested the patch, code looks good, can't see anything go wrong

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x and 8.x. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jmev’s picture

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?