From fd59c24a902bc0383062a44b854f2ae8da5c85ee Mon Sep 17 00:00:00 2001 From: astanley Date: Fri, 30 May 2025 10:23:51 -0300 Subject: [PATCH] hardened error checking --- .../Action/GenerateImageMediaDimensions.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Plugin/Action/GenerateImageMediaDimensions.php b/src/Plugin/Action/GenerateImageMediaDimensions.php index 4ca93c5..c4fbcd9 100644 --- a/src/Plugin/Action/GenerateImageMediaDimensions.php +++ b/src/Plugin/Action/GenerateImageMediaDimensions.php @@ -66,19 +66,22 @@ final class GenerateImageMediaDimensions extends ActionBase implements Container * Action execution. */ public function execute(ContentEntityInterface $entity = NULL): void { - $height = $entity->get('field_height')->getValue()[0]['value']; - $width = $entity->get('field_width')->getValue()[0]['value']; + $height = $entity->get('field_height')->value; + $width = $entity->get('field_width')->value; $field = $entity->hasField('field_media_file') ? 'field_media_file' : 'field_media_image'; if (!$width || !$height) { if ($entity->hasField($field) && !$entity->get($field)->isEmpty()) { $file = $entity->get($field)->entity; $realpath = $this->fileSystem->realpath($file->getFileUri()); - $dimensions = getimagesize($realpath); - if ($dimensions) { - $entity->set('field_height', $dimensions[1]); - $entity->set('field_width', $dimensions[0]); - $entity->save(); + if ($realpath) { + $dimensions = getimagesize($realpath); + if ($dimensions) { + $entity->set('field_height', $dimensions[1]); + $entity->set('field_width', $dimensions[0]); + $entity->save(); + } } + } } }