Skip to content

Commit

Permalink
UHF-10724: Add the image author information for article hero
Browse files Browse the repository at this point in the history
  • Loading branch information
teroelonen committed Dec 16, 2024
1 parent 048e03f commit b2d7a5c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function helfi_node_news_article_theme() : array {
'title' => NULL,
'description' => NULL,
'image' => NULL,
'image_author' => NULL,
'published_time' => NULL,
'html_published_time' => NULL,
'updated_time' => NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Drupal\helfi_node_news_article\Plugin\Block;

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Exception\MissingDataException;
use Drupal\helfi_node_news_article\Entity\Node\NewsArticle;
use Drupal\helfi_platform_config\Plugin\Block\ContentBlockBase;

Expand Down Expand Up @@ -69,12 +71,28 @@ public function build() : array {
?->first()
?->view($image_display_options);

$image_author = '';

$image_author_name = $media
?->get('field_photographer')
?->first()
?->getString();

if(!empty($image_author_name)) {
$image_author = t(
'Image: @image_author',
['@image_author' => $image_author_name],
['context' => 'Helfi Paragraphs Hero']
);
}

$build['news_article_hero_block'] = [
'#theme' => 'news_article_hero_block',
'#title' => $entity->label(),
'#description' => $entity->get('field_lead_in')?->first()?->view(),
'#design' => $entity->get('field_hero_design')?->first()?->getString(),
'#image' => $image,
'#image_author' => $image_author,
'#published_time' => $entity->getPublishedHumanReadable(),
'#html_published_time' => $entity->getPublishedMachineReadable(),
'#updated_time' => $entity->getUpdatedHumanReadable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
title: title,
description: lead_in,
image: image,
image_author: image_author,
published_time: published_time,
html_published_time: html_published_time,
updated_time: updated_time,
Expand Down

0 comments on commit b2d7a5c

Please sign in to comment.