Skip to content

Commit

Permalink
UHF-9712: Fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrsky committed Mar 12, 2024
1 parent 3e1480b commit a6eb3fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions helfi_platform_config.tokens.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
14 changes: 10 additions & 4 deletions modules/helfi_platform_config_base/src/Token/NodeImageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ 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) &&
$node->field_liftup_image->entity instanceof MediaInterface &&
$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') &&
Expand All @@ -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') &&
Expand All @@ -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;
Expand Down

0 comments on commit a6eb3fd

Please sign in to comment.