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
- 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). - Run cron (
drush cron). No PDF or queued item is needed: core'sCron::processQueues()instantiates every cron queue worker on each run. - 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.
| Comment | File | Size | Author |
|---|---|---|---|
| media_pdf_thumbnail-entity-type-manager-interface.patch | 412 bytes | drumanuel |
Comments
Comment #2
drumanuel commentedComment #5
sgostanyan commentedComment #6
sgostanyan commented