- Issue created by @david.muffley
- Assigned to shiv_yadav
- Issue was unassigned.
- First commit to issue fork.
- Status changed to Closed: works as designed
6 months ago 7:11am 11 June 2024
When generating a PDF thumbnail from an entity directly, MediaPdfThumbnailImageManager::getPdfImage can throw an uncaught exception, and MediaPdfThumbnailImageManager::createPdfImageEntity can create an invalid pdf_image_entity entity.
Create a new media entity with the expected file field filled out (below this is 'field_media_file'). Without saving the entity try to generate the thumbnail.
\Drupal::service('media_pdf_thumbnail.image.manager')->createThumbnail($entity, 'field_media_file', 'jpg', 1)
This code will throw an uncaught exception:
Drupal\Core\Database\InvalidQueryException: Query condition 'pdf_image_entity.referenced_entity_revision_id IN ()' cannot be empty. in Drupal\Core\Database\Query\Condition->condition() (line 117 of /opt/drupal/web/core/lib/Drupal/Core/Database/Query/Condition.php).
This is because $entity->getLoadedRevisionId() returns NULL unless the entity has been loaded, or had its loadedRevisionId attribute set.
If this issue is worked around in some way, such as saving the entity and then using $entity->getRevisionId(), createPdfImageEntity still has issues if $entity or $fileEntity haven't been saved yet as $entity->id() or $fileEntity->id() return NULL. This will then create a pdf_image_entity with no value for those fields, and so the entity will never match anything.
Closed: works as designed
6.0
Code