Trying to remove an image file from a Media entity results in this error:

Error: Call to a member function language() on null in Drupal\exif\ExifContent->getFileUriAndLanguage() (line 376 of /home/stencilarchive/stencilarchive.org/web/modules/contrib/exif/src/ExifContent.php).

Issue fork exif-3569085

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

codesmith created an issue. See original summary.

codesmith’s picture

This happened after upgrading from Drupal 10 to Drupal 11.3

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

nickolaj’s picture

Status: Active » Needs review

Added null check in `getFileUriAndLanguage()` to skip processing when file entity no longer exists (e.g., when image is removed from Media).

damienmckenna’s picture

Thank you for the merge request, we'll add it to the next release.

csakiistvan’s picture

Assigned: Unassigned » csakiistvan
csakiistvan’s picture

Assigned: csakiistvan » Unassigned
Status: Needs review » Reviewed & tested by the community

Environment

  • Drupal: 11.4.4
  • PHP: 8.5.5
  • Database: MariaDB 10.11.16
  • DDEV: v1.25.2
  • Exif: 8.x-2.7
  • Browser: Chrome

Prerequisites

  • Install and enable Exif 8.x-2.7 together with the core media module.
  • Enable Exif synchronisation for the Image media type and allow metadata updates on existing entities:
    ddev drush config:set exif.settings mediatypes.image image -y
    ddev drush config:set exif.settings update_metadata 1 -y
  • Add a plain text field field_model to the Image media type and set its widget on the default form display to Exif readonly, with Exif field = naming_convention and Image field = field_media_image.
  • Create an Image media entity with an uploaded JPEG.

Steps

  1. Apply the fix from MR !15: getFileUriAndLanguage() skips image field deltas whose referenced file entity is missing instead of dereferencing NULL.
  2. Rebuild caches: ddev drush cr
  3. Go to /media/1/edit for the Image media entity created above.
  4. Press the Remove button under the image.
  5. Check /admin/reports/dblog for PHP errors.

Expected results

  • The Remove button removes the image via AJAX and the form is rebuilt normally.
  • No PHP error or warning is written to the log.
  • Saving without an image shows the normal Drupal validation message "Image field is required.".

Actual results

Before the fix, pressing Remove aborted the AJAX request with "Oops, something went wrong." and logged Warning: Trying to access array offset on null followed by Error: Call to a member function language() on null in Drupal\exif\ExifContent->getFileUriAndLanguage(), raised from getMediaMetadata() in exif_form_alter() during the form rebuild. After the fix the image is removed cleanly, the form rebuilds, the log stays empty, and saving only produces the expected "Image field is required." validation message.


Testing produced with the assistance of an LLM.

damienmckenna’s picture

Version: 8.x-2.7 » 8.x-2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed. Thank you.

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.