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.

Image

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?

Command icon 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

UriDrupal created an issue. See original summary.

uridrupal’s picture

I was able to solve the by adding a validation

if (method_exists($image,'getValue')) {}

But I'm not really sure this is the way

uridrupal’s picture

Issue summary: View changes
uridrupal’s picture

Issue summary: View changes
uridrupal’s picture

I have created this Patch, someone should review it!

sebastix’s picture

StatusFileSize
new1.71 KB

Maybe 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.

acbramley’s picture

Version: 8.x-1.1 » 8.x-1.x-dev
Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new1.77 KB
new1.07 KB

Came 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.

stijnstroobants’s picture

Thanks for the patches.
This week I'll try to find some time to review.

grimreaper’s picture

Status: Needs review » Postponed (maintainer needs more info)

Hello,

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.

stewest’s picture

When 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.

The website encountered an unexpected error. Please try again later.
Error: Call to undefined method stdClass::getValue() in animated_gif_preprocess_image_formatter() (line 18 of modules/contrib/animated_gif/animated_gif.module).

When I uninstall the Animated GIF module, I am able to browse for files again.

stewest’s picture

Status: Postponed (maintainer needs more info) » Reviewed & tested by the community

I've applied this patch #7 3056477-7.patch and it solves the issue. I was using 8.x-1.4

grimreaper’s picture

Assigned: Unassigned » grimreaper

Thanks for the feedback.

Checking.

grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Reviewed & tested by the community » Postponed (maintainer needs more info)
StatusFileSize
new182.22 KB
new144.69 KB

Sorry, 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.

ruuds’s picture

StatusFileSize
new1.25 KB

The patch of #7 didn't work with 1.6.0 anymore, so i've created a new one based on the old patches.

acbramley’s picture

Status: Postponed (maintainer needs more info) » Needs review

Yeah this is still an issue. It happens for me on view lists of File entities.

grimreaper’s picture

Status: Needs review » Postponed (maintainer needs more info)

Hello,

And it still requires detailed steps to reproduce from a fresh Drupal install.

s_leu’s picture

Issue summary: View changes
StatusFileSize
new447.72 KB

I'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 like

if (empty($variables['item']) || $variables['item'] instanceof \Drupal\image\Plugin\Field\FieldType\ImageItem) {
  return;
}

would 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

  1. $ drush si -y && drush en -y admin_toolbar_tools, media, component_library, media_library && drush uli
  2. Add a media reference field to the article content type and make sure it's using the Media Library widget on the node form
  3. Create an article node adding an image media in the media field
  4. Enable the animated_gif module
  5. Refer to the following screencast for further steps

s_leu’s picture

Status: Postponed (maintainer needs more info) » Needs work
jansete’s picture

Status: Needs work » Needs review
StatusFileSize
new1.3 KB

Reroll patch for the last version.

grimreaper’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
grimreaper’s picture

Status: Needs review » Postponed (maintainer needs more info)
StatusFileSize
new7.31 MB

Hi,

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.

jansete’s picture

I 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

ruuds’s picture

StatusFileSize
new1.39 KB

See the attached patch for a version which works with the 2.x branch.

grimreaper’s picture

Title: Error with module EntityBrowser » Error when item is not set
Version: 2.0.x-dev » 2.1.x-dev
Assigned: Unassigned » grimreaper
Status: Postponed (maintainer needs more info) » Needs work

I had been able to get the issue with Layout Builder preview.

When displaying a media entity reference field with the "Thumbnail" formatter.

grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Needs work » Needs review
grimreaper’s picture

StatusFileSize
new1.97 KB

Patch for Composer usage.

grimreaper’s picture

StatusFileSize
new126.82 KB

I 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.

grimreaper’s picture

andreasderijcke made their first commit to this issue’s fork.

andreasderijcke’s picture

I 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.

nicxvan made their first commit to this issue’s fork.

nicxvan’s picture

I updated this to use method_exists instead of properties, because it is checking a method not a property.

grimreaper’s picture

Version: 2.1.x-dev » 2.x-dev
Status: Needs review » Needs work

Hello,

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.

grimreaper’s picture

Assigned: Unassigned » grimreaper
grimreaper’s picture

Version: 2.x-dev » 2.1.x-dev

With the refactoring done on 2.x this branch is not affected.

Will merge on 2.1.x and then release 2.1.1

  • grimreaper committed c725247c on 2.1.x
    fix: #3056477 Error when item is not set
    
    By: uridrupal
    By: sebastix
    By...
grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Needs work » Fixed
Issue tags: -Needs tests

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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