Skip to content

Commit

Permalink
Merge pull request #1137 from City-of-Helsinki/UHF-10887
Browse files Browse the repository at this point in the history
UHF-10887: remove the hearings on wrong language -feature
  • Loading branch information
rpnykanen authored Dec 13, 2024
2 parents d35f85e + 7c32f61 commit cd8b74a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 94 deletions.
34 changes: 0 additions & 34 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -1840,40 +1840,6 @@ function hdbt_preprocess_paragraph__job_search(array &$variables) {
}
}

/**
* Implements hook_preprocess_HOOK().
*/
function hdbt_preprocess_external_entity__helfi_hearings(array &$variables) {
$language = \Drupal::languageManager()
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId();
$entity = $variables['external_entity'];
$hearingLangcode = $entity->get('langcode')->value;
if ($hearingLangcode && $hearingLangcode == $language) {
return;
}
$existingLanguages = explode(',', $entity->get('existing_translations')->value);

if (in_array("fi", $existingLanguages) && in_array("en", $existingLanguages) && count($existingLanguages) === 2) {
$variables['available_in_languages'] = t('Hearing only available in Finnish and English', [], ['context' => 'Hearing available in languages']);
}
if (in_array("fi", $existingLanguages) && in_array("sv", $existingLanguages) && count($existingLanguages) === 2) {
$variables['available_in_languages'] = t('Hearing only available in Finnish and Swedish', [], ['context' => 'Hearing available in languages']);
}
if (in_array("en", $existingLanguages) && in_array("sv", $existingLanguages) && count($existingLanguages) === 2) {
$variables['available_in_languages'] = t('Hearing only available in English and Swedish', [], ['context' => 'Hearing available in languages']);
}
if (in_array("fi", $existingLanguages) && count($existingLanguages) === 1) {
$variables['available_in_languages'] = t('Hearing only available in Finnish', [], ['context' => 'Hearing available in languages']);
}
if (in_array("en", $existingLanguages) && count($existingLanguages) === 1) {
$variables['available_in_languages'] = t('Hearing only available in English', [], ['context' => 'Hearing available in languages']);
}
if (in_array("sv", $existingLanguages) && count($existingLanguages) === 1) {
$variables['available_in_languages'] = t('Hearing only available in Swedish', [], ['context' => 'Hearing available in languages']);
}
}

/**
* Implements hook_theme_suggestions_alter() for container.
*/
Expand Down
85 changes: 25 additions & 60 deletions templates/content/external-entity--helfi-hearings.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,63 +18,28 @@
{% set card_unpublished_on = '-' %}
{% endif %}

{% if available_in_languages %}
{% embed '@hdbt/component/card.twig' with {
card_modifier_class: card_hearing_classes|join(' '),
card_title: content.title[0]['#context'].value,
card_title_lang: content.langcode[0]['#context'].value,
card_image: content.main_image,
card_url: content.url[0]['#context'].value,
card_url_external: true,
card_metas: [
{
icon: 'clock',
label: 'Opened'|t({}, {'context': 'Label for hearing opened date'}),
content: card_published_on,
},
{
icon: 'clock',
label: 'Closes'|t({}, {'context': 'Label for hearing closes date'}),
content: card_unpublished_on,
},
{
icon: 'speechbubble-text',
label: 'Activity'|t({}, {'context': 'Label for hearing activity row'}),
content: card_hearing_comments,
},
],
card_tags: [
{
tag: available_in_languages,
color: 'alert',
}
],
} %}
{% endembed %}
{% else %}
{% embed '@hdbt/component/card.twig' with {
card_modifier_class: card_hearing_classes|join(' '),
card_title: content.title[0]['#context'].value,
card_image: content.main_image,
card_url: content.url[0]['#context'].value,
card_url_external: true,
card_metas: [
{
icon: 'clock',
label: 'Opened'|t({}, {'context': 'Label for hearing opened date'}),
content: card_published_on,
},
{
icon: 'clock',
label: 'Closes'|t({}, {'context': 'Label for hearing closes date'}),
content: card_unpublished_on,
},
{
icon: 'speechbubble-text',
label: 'Activity'|t({}, {'context': 'Label for hearing activity row'}),
content: card_hearing_comments,
},
]
} %}
{% endembed %}
{% endif %}
{% embed '@hdbt/component/card.twig' with {
card_modifier_class: card_hearing_classes|join(' '),
card_title: content.title[0]['#context'].value,
card_image: content.main_image,
card_url: content.url[0]['#context'].value,
card_url_external: true,
card_metas: [
{
icon: 'clock',
label: 'Opened'|t({}, {'context': 'Label for hearing opened date'}),
content: card_published_on,
},
{
icon: 'clock',
label: 'Closes'|t({}, {'context': 'Label for hearing closes date'}),
content: card_unpublished_on,
},
{
icon: 'speechbubble-text',
label: 'Activity'|t({}, {'context': 'Label for hearing activity row'}),
content: card_hearing_comments,
},
]
} %}
{% endembed %}

0 comments on commit cd8b74a

Please sign in to comment.