Skip to content

Commit

Permalink
Merge pull request #656 from City-of-Helsinki/UHF-9963
Browse files Browse the repository at this point in the history
UHF-9963: You might be interested in blocks new design
  • Loading branch information
rpnykanen authored Jul 9, 2024
2 parents 6d4c674 + 6a65f64 commit 2dc9031
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ dependencies:
- hdbt_subtheme
id: hdbt_subtheme_aipoweredrecommendations
theme: hdbt_subtheme
region: after_content
weight: -12
region: content
weight: 1
provider: null
plugin: helfi_recommendations
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ dependencies:
- hdbt_subtheme
id: hdbt_subtheme_views_block__frontpage_news_of_interest
theme: hdbt_subtheme
region: after_content
weight: -12
region: content
weight: 1
provider: null
plugin: 'views_block:frontpage_news-of_interest'
settings:
Expand Down
19 changes: 19 additions & 0 deletions conf/cmi/views.view.frontpage_news.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,11 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
pager:
type: some
options:
offset: 0
items_per_page: 3
empty: { }
sorts:
published_at:
Expand Down Expand Up @@ -2036,10 +2041,24 @@ display:
operator: AND
groups:
1: AND
style:
type: default
options:
row_class: ''
default_row_class: true
uses_fields: true
row:
type: 'entity:node'
options:
relationship: none
view_mode: teaser
defaults:
empty: false
title: false
pager: false
group_by: false
style: false
row: false
fields: false
sorts: false
arguments: false
Expand Down
2 changes: 2 additions & 0 deletions public/modules/custom/helfi_annif/helfi_annif.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ dependencies:
- drupal:text
- drupal:language
- helfi_api_base:helfi_api_base
'interface translation project': helfi_annif
'interface translation server pattern': modules/custom/helfi_annif/translations/%language.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Block\Attribute\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\Context\EntityContextDefinition;
use Drupal\Core\Plugin\ContextAwarePluginInterface;
Expand Down Expand Up @@ -37,6 +38,7 @@ public function __construct(
$plugin_id,
$plugin_definition,
private readonly RecommendationManager $recommendationManager,
private readonly EntityTypeManagerInterface $entityTypeManager,
private readonly AccountInterface $currentUser,
private readonly LoggerInterface $logger,
) {
Expand All @@ -49,6 +51,7 @@ public function __construct(
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) : static {
return new static($configuration, $plugin_id, $plugin_definition,
$container->get(RecommendationManager::class),
$container->get('entity_type.manager'),
$container->get('current_user'),
$container->get('logger.channel.helfi_annif'),
);
Expand All @@ -60,10 +63,10 @@ public static function create(ContainerInterface $container, array $configuratio
public function build() : array {
$node = $this->getContextValue('node');

// @todo #UHF-9964 Lisätään suosittelulohkon piilotustoiminto.
// @todo #UHF-9964 Add recommendation block hiding feature.
$response = [
'#theme' => 'recommendations_block',
'#title' => $this->t('You might be interested in'),
'#title' => $this->t('You might be interested in', [], ['context' => 'Recommendations block title']),
];

$recommendations = [];
Expand All @@ -79,7 +82,14 @@ public function build() : array {
return $this->handleNoRecommendations($response);
}

$response['#rows'] = $recommendations;
$nodes = [];
// We want to render the recommendation results as nodes
// so that all fields are correctly preprocessed.
foreach ($recommendations as $recommendation) {
$view_builder = $this->entityTypeManager->getViewBuilder('node');
$nodes[] = $view_builder->view($recommendation, 'teaser');
}
$response['#rows'] = $nodes;
return $response;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
{% for row in rows %}
{# Created date and modified date #}
{% set published_at = row.published_at.value %}
{% if published_at is not empty %}
{% set html_published_at %}
<time datetime="{{ published_at|format_date('custom', 'Y-m-d') ~ 'T' ~ published_at|format_date('custom', 'H:i') }}" class="news-listing__datetime news-listing__datetime--published" {{ alternative_language ? create_attribute(({ 'lang': lang_attributes.fallback_lang, 'dir': lang_attributes.fallback_dir })) }}>
<span class="visually-hidden">{{ 'Published'|t({}, {'context': 'The helper text before the node published timestamp'}) }}</span>
{{ published_at|format_date('publication_date_format') }}
</time>
{% endset %}
{% else %}
{% set html_published_at = '-' %}
{% endif %}

{% set card_url = url('entity.node.canonical', {'node': row.id})['#markup'] %}

{% embed '@hdbt/component/card.twig' with {
card_modifier_class: 'news-listing__item',
card_title_level: 'h3',
card_title: row.title.value,
card_url: card_url,
card_metas: [
{
icon: 'clock',
label: 'Published'|t({}, {'context': 'Label for news card published time'}),
content: html_published_at
},
],
} %}
{% endembed %}
{{ row }}
{% endfor %}
6 changes: 6 additions & 0 deletions public/modules/custom/helfi_annif/translations/fi.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
msgid ""
msgstr ""

msgctxt "Recommendations block title"
msgid "You might be interested in"
msgstr "Sinua voisi kiinnostaa"
6 changes: 6 additions & 0 deletions public/modules/custom/helfi_annif/translations/sv.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
msgid ""
msgstr ""

msgctxt "Recommendations block title"
msgid "You might be interested in"
msgstr "Du kanske är intresserad av"
2 changes: 1 addition & 1 deletion public/themes/custom/hdbt_subtheme/dist/css/styles.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2dc9031

Please sign in to comment.