diff --git a/helfi_platform_config.tokens.inc b/helfi_platform_config.tokens.inc index 91cbf3b1a..7d8844a6c 100644 --- a/helfi_platform_config.tokens.inc +++ b/helfi_platform_config.tokens.inc @@ -10,6 +10,7 @@ declare(strict_types=1); use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Render\BubbleableMetadata; +use Drupal\paragraphs\ParagraphInterface; /** * Implements hook_token_info(). diff --git a/modules/helfi_platform_config_base/src/Token/NodeImageBuilder.php b/modules/helfi_platform_config_base/src/Token/NodeImageBuilder.php index 9054a0466..8dc8d6d90 100644 --- a/modules/helfi_platform_config_base/src/Token/NodeImageBuilder.php +++ b/modules/helfi_platform_config_base/src/Token/NodeImageBuilder.php @@ -58,7 +58,7 @@ public function buildUrl(EntityInterface $entity): ?string { * @return \Drupal\file\FileInterface|null * Image entity. */ - public function getImage(NodeInterface $node) : ?FileInterface { + private function getImage(NodeInterface $node) : ?FileInterface { if ( $node->hasField('field_liftup_image') && isset($node->field_liftup_image->entity) && @@ -66,7 +66,9 @@ public function getImage(NodeInterface $node) : ?FileInterface { $node->field_liftup_image->entity->hasField('field_media_image') ) { // If liftup image has an image set, use it as the shareable image. - return $node->field_liftup_image->entity->field_media_image->entity; + $file = $node->field_liftup_image->entity->field_media_image->entity; + assert($file instanceof FileInterface); + return $file; } elseif ( $node->hasField('field_image') && @@ -75,7 +77,9 @@ public function getImage(NodeInterface $node) : ?FileInterface { $node->field_image->entity->hasField('field_media_image') ) { // If the node has an image, use that. - return $node->field_image->entity->field_media_image->entity; + $file = $node->field_image->entity->field_media_image->entity; + assert($file instanceof FileInterface); + return $file; } elseif ( $node->hasField('field_organization') && @@ -84,7 +88,9 @@ public function getImage(NodeInterface $node) : ?FileInterface { ) { // Use the image from the taxonomy term. $taxonomy_term = $node->field_organization->entity; - return $taxonomy_term->field_default_image->entity; + $file = $taxonomy_term->field_default_image->entity; + assert($file instanceof FileInterface); + return $file; } return NULL;