Hi, I am new in Drupal. I got php notice in log message like below
Notice: Undefined index: uri in theme_image_formatter() (line 602 of /home/lensaker/public_html/ojual.com/modules/image/image.field.inc).
and
Notice: Undefined index: uri in image_field_formatter_view() (line 572 of /home/lensaker/public_html/ojual.com/modules/image/image.field.inc).
every time i upload an image.
Currently I fix it by a condition:
$item['uri'] = isset($item['uri']) ? $item['uri'] : "";
the log message now silence, but is this correct or is there other good solution? ie update to some version?
I use Drupal 7.14
Thanks
Comment | File | Size | Author |
---|---|---|---|
#13 | image-preview-missing-1678686-12.patch | 890 bytes | vaartio |
#11 | image-preview-missing-1678686-11.patch | 759 bytes | ShaneOnABike |
#8 | image-preview-missing-1678686-8.patch | 597 bytes | yingtho |
Comments
Comment #1
SpleshkaI got this message too (Notice: Undefined index: uri in theme_image_formatter() (line 602 of path-to-drupal/modules/image/image.field.inc).
See code:
No check for empty $item['uri'];
Comment #2
SpleshkaSorry, I found a bug. I called node_view() on hook_node_update(). That was my mistake.
Hope that it will help someone.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedMe too (Notice: Undefined index: uri in theme_image_formatter() (line 602 of path-to-drupal/modules/image/image.field.inc).
Though unlike Spleshka, I am not using any theming hooks.
I think that it's causing my image token to output
http://dev.portside.org/sites/default/files/styles/large/public
when it should go to
http://dev.portside.org/sites/default/files/styles/large/public/field/image/image-file
Comment #4
catchStill a valid bug in 7.x. Code hasn't changed in 8.x either. Just reproduced when uploading an image on a very simple install.
Comment #5
swentel CreditAttribution: swentel commentedLooking
Comment #6
swentel CreditAttribution: swentel commentedhmm
image_field_formatter_view
doesn't even exist anymore in D8 .. catch, could your error be related to #1885644: ImageStyle::uri() is broken and has no coverageComment #7
claudiu.cristeaI cannot reproduce this error in D8. Feel free to move it back to D8 if I was wrong.
Comment #8
yingtho CreditAttribution: yingtho commentedPlease see enclosed fix to this issue. It seems that the uri is empty somehow.
Comment #9
Niremizov CreditAttribution: Niremizov commentedThis bug can be also reproduced when using views. Try to output Image field, and group it by FID... But patch, solves this.
Comment #11
ShaneOnABike CreditAttribution: ShaneOnABike commentedFor me the patch didn't resolve my issue mainly because it was occuring in theme_image_formatter...
But verifying that a proper FID exists within the $item array seems to have reduced the problem... by changing the code to
I combined both my patch fix and the other one to keep some consistancy
Comment #13
vaartio CreditAttribution: vaartio commentedI have the same case with theme_image_formatter(). However, I recommend that we should check the existence of $item['uri'] rather than fid, since uri is the property that theme_image_formatter uses for path.
Comment #14
dcam CreditAttribution: dcam commentedActivating Testbot.
Comment #15
Christopher Riley CreditAttribution: Christopher Riley commentedAny idea when this patch will become "Official"?
Comment #16
vaartio CreditAttribution: vaartio commentedComment #19
David_Rothstein CreditAttribution: David_Rothstein commentedSeems like we need to look into the root cause of this bug more. What is the fundamental reason that $item['uri'] is missing in the first place?
Comment #20
jcfiala CreditAttribution: jcfiala commentedIf it helps, I'm getting it when I add an image field to a comment, and then preview the comment. Throwing in a dpm, here's what's in my item:
The fid points to a valid row in file_managed, but the file information just hasn't been loaded.
Comment #21
formatC'vt CreditAttribution: formatC'vt commentedConfirm bug with image field and comment preview. it's are easy to reproduce:
1) Install drupal (without any contrib module)
2) add image field to comment
3) upload an image to comment and click 'preview'
4) Home » Administration » Reports
Notice: Undefined index: uri in theme_image_formatter() (line 602 of /home/s800caa97026f0d7/www/modules/image/image.field.inc).
Patch fix this.
Comment #22
Dave ReidThis would be resolved by the patch in #920840: Broken images displayed and PHP notices when file/image field values are missing which would remove the missing file item from the field value array completely.
Comment #23
ShaunDychko CreditAttribution: ShaunDychko commentedThis is not a duplicate issue I don't think. #920840: Broken images displayed and PHP notices when file/image field values are missing deals with the case where the file doesn't load. In my use case there is a valid image which loads just fine, and the
$item['fid']
was populated correctly, although$item['uri']
wasn't for some reason. The patch in #13 removes the error message nicely.Perhaps what makes my use case a bit different is that, given an image field in user accounts, there's a
user_view
anddrupal_render
called for a particular display mode each time the user account is updated in order to update a custom cached version of their profile for a map marker popup. Maybe this unconventional way of calling those functions from within hook_user_update() causes the$item['fid']
to get populated, but not$item['uri']
? The profile image field uses the private file system, if that makes a difference.In any case #13 solves the pesky error message. Thank you!
Comment #24
Chris Matthews CreditAttribution: Chris Matthews commentedIs this a duplicate of #920840 or does this still need review for the patch in #13 to be committed?
Comment #25
Nathan Tsai CreditAttribution: Nathan Tsai commentedEncountered this today. Fixed using the patch in #8.
Jun 18, 2018:
The patch was overridden when the core was updated and used an alternate solution.
To fix error when aggregating images fields, (or possibly file fields), in views: change "Group column" from Fid to Entity ID.
Comment #26
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedI digged into this a little bit deeper and regarding #20 and #21 use-cases, there seems to be a bug in
function comment_preview($comment)
.This function takes a
$comment
as a parameter, but this object contains only values from the$form_state
data.If we compare that with
function node_preview($node)
which is the same function for the node preview and where the preview with image is working, we will see, that in this function there is this code used:This code will ensure that all fields gets all values correctly populated. This call is missing in
comment_preview()
function. If we add this tocomment_preview()
function (for example after thenode_load
call), the problem with the broken image preview should be gone:But it seems like there are more different scenarios mentioned - from views, user images, up to these comments. Personally I do not like the approach of introducing a
file_load()
call to theimage_field_formatter_view()
, when URI is missing. This will mask all potential problems, not solve them. I think the better approach should be to not render the image at all, if the URI is missing (like it is done intheme_image_formatter()
in the patch).Comment #27
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedAdding that
_field_invoke_multiple()
will also fix a usecase mentioned here: #1967176-4: Multiple stdClass::$filemime notices related to file fields and email display mode.