Hello,
We're having an issue when using this module with Contrib Module Entity Browser.
Error: Call to undefined method stdClass::getValue() in animated_gif_preprocess_image_formatter() (line 11 of /app/docroot/modules/contrib/animated_gif/animated_gif.module)
This fatal error is ocurring when we try to access File Listing.
Basically the object is getting $image = $variables['item']; does not have the getValue() method and it's throwing a fatal error.
It would see that when chosing a file that has already been loaded, it's passing through this module and causing an error.
I was able to solve the issue by adding a validation, if the object doesn't have getValue() method, don't run the code.
Is there a better approach to solve this issue?
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | Capture d’écran du 2025-01-08 15-47-22.png | 126.82 KB | grimreaper |
| #27 | animated_gif-3056477-27.patch | 1.97 KB | grimreaper |
| #23 | entity-browser-error-2.x.patch | 1.39 KB | ruuds |
| #21 | Peek 23-04-2023 21-27.gif | 7.31 MB | grimreaper |
| #19 | animated_gif-error-with-multivalues-fields-3056477-19.patch | 1.3 KB | jansete |
Issue fork animated_gif-3056477
Show commands
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 #2
uridrupal commentedI was able to solve the by adding a validation
if (method_exists($image,'getValue')) {}
But I'm not really sure this is the way
Comment #3
uridrupal commentedComment #4
uridrupal commentedComment #5
uridrupal commentedI have created this Patch, someone should review it!
Comment #6
sebastixMaybe it's better to get the File entity directory from the variables array and skip the usage of the getValue method?
See the patch I've made.
Comment #7
acbramley commentedCame across this same issue, 6 fixed it but had PHPCS issues - this fixes those. I think this module could do with a few automated tests as well so adding a tag for that.
Comment #8
stijnstroobantsThanks for the patches.
This week I'll try to find some time to review.
Comment #9
grimreaperHello,
Thanks everyone for reporting the issue and providing patches.
But can you please provide detailed steps to reproduce the issue starting from a fresh Drupal standard install?
Or what is the entity browser configuration and view listing?
Because I tried to reproduce the bug and I didn't manage to obtain the error.
Comment #10
stewestWhen trying to browse for images using the Entity Browser (Entity Embed from Wysiwyg), I get an error when trying to read from the Media Library [Uploads work fine].
I'd expect to see the view listing of media images in the Media Library - but instead get an error message.
When I uninstall the Animated GIF module, I am able to browse for files again.
Comment #11
stewestI've applied this patch #7 3056477-7.patch and it solves the issue. I was using 8.x-1.4
Comment #12
grimreaperThanks for the feedback.
Checking.
Comment #13
grimreaperSorry, but I still need detailed steps to reproduce the bug.
As in comment 10, it is written "from the Media Library", I don't know if this is still on Entity Browser or the core media library. So I tried with boths and it works in boths cases (without the patch), see attached screenshots.
Therefore, this still needs detailed steps to reproduce starting from a standard Drupal install.
Comment #14
ruuds commentedThe patch of #7 didn't work with 1.6.0 anymore, so i've created a new one based on the old patches.
Comment #15
acbramley commentedYeah this is still an issue. It happens for me on view lists of File entities.
Comment #16
grimreaperHello,
And it still requires detailed steps to reproduce from a fresh Drupal install.
Comment #17
s_leu commentedI'm encountering a similar error but in a different scenario:
Error: Call to a member function getValue() on array in animated_gif_preprocess_image_formatter()Anyway I think the solution for the error in the issue description would also solve that error I found. As for the patch in #14, I think that this won't be sufficient and is lacking a basic validation of whatever is inside
$variables['item']is actually an object or even is set at all. So maybe something likewould solve the error described in the IS as well as the one I'm encountering.
In my case, the steps to replicate this are the following (it includes other contribs, so not sure if it's a great example):
On Vanilla Drupal 9.5.x
Comment #18
s_leu commentedComment #19
jansete commentedReroll patch for the last version.
Comment #20
grimreaperComment #21
grimreaperHi,
I tried to reproduce from the steps provided in comment 17.
No problem. I tried with image field, image field with entity browser, media field.
In this gif screencast you will see my entity browser view configuration.
Comment #22
jansete commentedI remember that for me I could reproduce with fields that have multiple fields, maybe entity reference with multiple images in the field, because in xdebug y showed an entitties array instead a single entity, for me the last patch worked
Comment #23
ruuds commentedSee the attached patch for a version which works with the 2.x branch.
Comment #24
grimreaperI had been able to get the issue with Layout Builder preview.
When displaying a media entity reference field with the "Thumbnail" formatter.
Comment #26
grimreaperComment #27
grimreaperPatch for Composer usage.
Comment #28
grimreaperI think the problem is deeper and not necessarily related to animated_gif.
Because once there is no more fatal error, I still have plenty of warnings from Core codebase, so I guess there is an alteration somewhere that "destroys" expected input data.
Comment #29
grimreaperPotentially related to #3170319: SVG-only image fields cause error with Layout Builder
Comment #31
andreasderijckeI made the checks a bit more specific, as it didn't suffice for Layout Builder. The
getValue()was still reached.It would be even better if we could check the object class instead of presence of the
getValue()method, but I don't know which one is expected.Comment #33
nicxvan commentedI updated this to use method_exists instead of properties, because it is checking a method not a property.
Comment #34
grimreaperHello,
I have incorporated the changes proposed here in #3561824: Code update on new 2.x branch for a 2.2.0 release (not yet done). It was needed for PHPStan.
Keeping this issue opened if someone want/can provide tests.
Comment #35
grimreaperComment #36
grimreaperWith the refactoring done on 2.x this branch is not affected.
Will merge on 2.1.x and then release 2.1.1
Comment #38
grimreaper