Problem/Motivation

We got an error on a page that was previously working fine.

Error: Call to a member function get() on null in Drupal\media_video_micromodal\Plugin\Field\FieldFormatter\MicromodalFieldFormatter->viewElements() (regel 324 van web/modules/contrib/media_video_micromodal/src/Plugin/Field/FieldFormatter/MicromodalFieldFormatter.php)

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

joshahubbers created an issue. See original summary.

joshahubbers’s picture

StatusFileSize
new951 bytes

The patch file for use in composer

joshahubbers’s picture

Status: Active » Needs review

scott_earnest’s picture

Hi and thank you for catching this. Maybe there was a referenced entity that was removed? I was able to duplicate the issue by zero-ing out the "target_id" so that it would not load the media or thumbnail correctly:

 // Load the media for the thumbnail, if it's media reference.
else {
+   $target_id = 0;            
    $thumbnail_media = $this->entityTypeManager->getStorage('media')->load($target_id);

Regarding your patch, I feel that the thumbnail_file_id needed to be set either way, even if to false, but further down needed some checks.

I have pushed a fix to the 1.x-dev branch.

Testing Instructions
- Use the MVM formatter with "Custom Thumbnail Media Reference" display
- Use the code block above to manually alter the target id
- Verify the page still loads, but the MVM item would not display since the thumbnail did not exist

  • 8e71e902 committed on 1.x
    Issue #3485050 by joshahubbers, scott_earnest: Error when no media item...
scott_earnest’s picture

Version: 1.1.1 » 1.x-dev
scott_earnest’s picture

Tested on:
Drupal 10.3.6
Drupal 11.0.5

RTBC +1

pushing this to new release

scott_earnest’s picture

Assigned: Unassigned » scott_earnest
Status: Needs review » Reviewed & tested by the community
scott_earnest’s picture

Version: 1.x-dev » 1.1.3
Assigned: scott_earnest » Unassigned
Status: Reviewed & tested by the community » Fixed
scott_earnest’s picture

Status: Fixed » Closed (fixed)
scott_earnest’s picture

Thanks @joshahubbers!

joshahubbers’s picture

Great. Thank you for the fix and your effort.