Download & Extend

Notice: Undefined index: path in theme_image_formatter()

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

Assigned to:Anonymous» webchick

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

#2

Version:7.0» 8.x-dev
Status:active» needs review

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.

AttachmentSizeStatusTest resultOperations
1124786-fix-notice.patch520 bytesIdleFAILED: [[SimpleTest]]: [MySQL] 31,599 pass(es), 0 fail(s), and 1 exception(es).View details

#3

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?

#4

Status:active» needs review

x-post!

#5

Version:7.0» 8.x-dev

#6

Status:needs review» needs work

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

#7

Title:Undefined index» Notice: Undefined index: path in theme_image_formatter()
Status:needs work» needs review

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

AttachmentSizeStatusTest resultOperations
noticefix-1124786.patch528 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 30,022 pass(es).View details

#8

Status:needs review» needs work

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

#9

Any updates on this issue?

#10

Status:needs work» needs review

#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

AttachmentSizeStatusTest resultOperations
image_error.png55.09 KBIgnored: Check issue status.NoneNone

#12

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

#13

Status:needs review» reviewed & tested by the community

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

#14

Status:reviewed & tested by the community» fixed

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

#15

Status:fixed» closed (fixed)

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?

nobody click here