Problem/Motivation

The $entityTypeManager property of MediaPdfThumbnailImageManager is typed to the concrete core class instead of the interface:

protected EntityTypeManager $entityTypeManager;

The constructor already accepts EntityTypeManager|EntityTypeManagerInterface (see #3105762), but the assignment to the property fails as soon as the injected service is not an instance of Drupal\Core\Entity\EntityTypeManager. This happens whenever another module decorates the entity_type.manager service with a class that implements EntityTypeManagerInterface without extending the core class.

One example is Trash 3.1.0, which decorates the service with Drupal\trash\TrashEntityTypeManager. With Trash enabled, the pdf_image_entity_generate queue worker fails on every cron run:

TypeError: Cannot assign Drupal\trash\TrashEntityTypeManager to property Drupal\media_pdf_thumbnail\Manager\MediaPdfThumbnailImageManager::$entityTypeManager of type Drupal\Core\Entity\EntityTypeManager in Drupal\media_pdf_thumbnail\Manager\MediaPdfThumbnailImageManager->__construct() (line 121 of modules/contrib/media_pdf_thumbnail/src/Manager/MediaPdfThumbnailImageManager.php)

As a result, PDF thumbnails are no longer generated.

Steps to reproduce

  1. Install media_pdf_thumbnail 7.0.1 on Drupal 11.3 or 11.4, together with any module that decorates entity_type.manager (e.g. Trash 3.1.0).
  2. Run cron (drush cron). No PDF or queued item is needed: core's Cron::processQueues() instantiates every cron queue worker on each run.
  3. Cron fails with the TypeError above.

Proposed resolution

Type the property (and its @var) as EntityTypeManagerInterface, consistent with the other classes in this module (PdfImageEntityPurgeManager, PdfImageEntityQueueForm, the field formatter). The constructor and setEntityTypeManager() could be simplified to the interface as well.

Remaining tasks

  • Review the attached patch / MR.
  • Commit.

Human note: this was found/generated by Claude Opus. I tested it and it seems legit.

Comments

drumanuel created an issue. See original summary.

drumanuel’s picture

Issue summary: View changes

sgostanyan’s picture

Status: Needs review » Patch (to be ported)
sgostanyan’s picture

Status: Patch (to be ported) » Fixed

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.