diff --git a/modules/oe_theme_content_call_proposals/oe_theme_content_call_proposals.module b/modules/oe_theme_content_call_proposals/oe_theme_content_call_proposals.module index 13c20137f..2dd136f9a 100644 --- a/modules/oe_theme_content_call_proposals/oe_theme_content_call_proposals.module +++ b/modules/oe_theme_content_call_proposals/oe_theme_content_call_proposals.module @@ -58,3 +58,21 @@ function oe_theme_content_call_proposals_node_view_alter(array &$build, EntityIn } } } + +/** + * Implements template_preprocess_node() for the CFP node type. + */ +function oe_theme_content_call_proposals_preprocess_node__oe_call_proposals__teaser(array &$variables): void { + if (!isset($variables['elements']['extra_field_oe_call_proposals_label_status'])) { + return; + } + $status = $variables['elements']['extra_field_oe_call_proposals_label_status'][0]; + $variant = _oe_theme_helper_prepare_status_variant($status['#name']); + if (empty($variant)) { + return; + } + $variables['badges'][] = [ + 'label' => $status['#label']->render(), + 'variant' => $variant, + ]; +} diff --git a/modules/oe_theme_content_call_tenders/oe_theme_content_call_tenders.module b/modules/oe_theme_content_call_tenders/oe_theme_content_call_tenders.module index 950bc1907..162237660 100644 --- a/modules/oe_theme_content_call_tenders/oe_theme_content_call_tenders.module +++ b/modules/oe_theme_content_call_tenders/oe_theme_content_call_tenders.module @@ -67,3 +67,21 @@ function _oe_theme_content_call_tenders_strike_deadline(array &$variables): void $variables['attributes']['class'] = ['ecl-u-type-strike']; } } + +/** + * Implements template_preprocess_node() for the CFT node type. + */ +function oe_theme_content_call_tenders_preprocess_node__oe_call_tenders__teaser(array &$variables): void { + if (!isset($variables['elements']['extra_field_oe_call_tenders_label_status'])) { + return; + } + $status = $variables['elements']['extra_field_oe_call_tenders_label_status'][0]; + $variant = _oe_theme_helper_prepare_status_variant($status['#name']); + if (empty($variant)) { + return; + } + $variables['badges'][] = [ + 'label' => $status['#label']->render(), + 'variant' => $variant, + ]; +} diff --git a/modules/oe_theme_content_consultation/oe_theme_content_consultation.module b/modules/oe_theme_content_consultation/oe_theme_content_consultation.module index 5171be8d3..bda6bf1ca 100644 --- a/modules/oe_theme_content_consultation/oe_theme_content_consultation.module +++ b/modules/oe_theme_content_consultation/oe_theme_content_consultation.module @@ -75,3 +75,21 @@ function oe_theme_content_consultation_preprocess_oe_theme_helper_in_page_naviga } } } + +/** + * Implements template_preprocess_node() for the Consultation node type. + */ +function oe_theme_content_consultation_preprocess_node__oe_consultation__teaser(array &$variables): void { + if (!isset($variables['elements']['extra_field_oe_consultation_label_status'])) { + return; + } + $status = $variables['elements']['extra_field_oe_consultation_label_status'][0]; + $variant = _oe_theme_helper_prepare_status_variant($status['#name']); + if (empty($variant)) { + return; + } + $variables['badges'][] = [ + 'label' => $status['#label']->render(), + 'variant' => $variant, + ]; +} diff --git a/modules/oe_theme_helper/oe_theme_helper.module b/modules/oe_theme_helper/oe_theme_helper.module index 947fd1453..ff5e59cb2 100644 --- a/modules/oe_theme_helper/oe_theme_helper.module +++ b/modules/oe_theme_helper/oe_theme_helper.module @@ -412,3 +412,55 @@ function oe_theme_helper_form_entity_view_display_edit_form_alter(&$form, FormSt } } } + +/** + * Implements hook_preprocess_HOOK(). + */ +function oe_theme_helper_preprocess_node(&$variables): void { + $node_bundles = [ + 'oe_call_proposals', + 'oe_call_tenders', + 'oe_consultation', + 'oe_event', + 'oe_news', + 'oe_organisation', + 'oe_page', + 'oe_person', + 'oe_policy', + 'oe_project', + 'oe_publication', + ]; + /** @var \Drupal\node\NodeInterface $node */ + $node = $variables['node']; + if (in_array($node->bundle(), $node_bundles) && $node->isSticky()) { + $variables['badges'] = [ + [ + 'label' => 'Highlighted', + 'variant' => 'highlight', + ], + ]; + } +} + +/** + * Retrieves the variant for the status badge. + * + * @param string $status + * The status name. + * + * @return string + * The variant. + */ +function _oe_theme_helper_prepare_status_variant(string $status): string { + switch ($status) { + case 'open': + return 'high'; + + case 'upcoming': + return 'medium'; + + case 'closed': + return 'low'; + } + return ''; +} diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-bg.po b/modules/oe_theme_helper/translations/oe_theme_helper-bg.po index a6dc30a4e..9d39f0e33 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-bg.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-bg.po @@ -521,3 +521,6 @@ msgstr "Прочетох и съм съгласен с условията за @ msgid "data protection terms" msgstr "защита на данните" + +msgid "Highlighted" +msgstr "Акценти" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-cs.po b/modules/oe_theme_helper/translations/oe_theme_helper-cs.po index 8df428d78..0aca45358 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-cs.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-cs.po @@ -521,3 +521,6 @@ msgstr "Obeznámil(a) jsem se s podmínkami, které se týkají @link" msgid "data protection terms" msgstr "ochrany údajů" + +msgid "Highlighted" +msgstr "Důležité" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-da.po b/modules/oe_theme_helper/translations/oe_theme_helper-da.po index 7ec184cb7..c3790a091 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-da.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-da.po @@ -521,3 +521,6 @@ msgstr "Jeg har læst og accepterer bestemmelserne om @link" msgid "data protection terms" msgstr "databeskyttelse" + +msgid "Highlighted" +msgstr "Fremhævet" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-de.po b/modules/oe_theme_helper/translations/oe_theme_helper-de.po index fa17deac8..9a8839ae5 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-de.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-de.po @@ -521,3 +521,6 @@ msgstr "Ich habe die @link gelesen und bin damit einverstanden" msgid "data protection terms" msgstr "Datenschutzbestimmungen" + +msgid "Highlighted" +msgstr "Hervorgehoben" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-el.po b/modules/oe_theme_helper/translations/oe_theme_helper-el.po index bfaac8d6b..1a6d0317d 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-el.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-el.po @@ -521,3 +521,6 @@ msgstr "Διάβασα τους @link και συμφωνώ" msgid "data protection terms" msgstr "όρους προστασίας δεδομένων" + +msgid "Highlighted" +msgstr "Με επισήμανση" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-es.po b/modules/oe_theme_helper/translations/oe_theme_helper-es.po index 17d5e2383..132c672f3 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-es.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-es.po @@ -521,3 +521,6 @@ msgstr "He leído y acepto las @link" msgid "data protection terms" msgstr "condiciones de protección de datos" + +msgid "Highlighted" +msgstr "Destacado" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-et.po b/modules/oe_theme_helper/translations/oe_theme_helper-et.po index 9ffb7f7d6..d475f2099 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-et.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-et.po @@ -521,3 +521,6 @@ msgstr "Olen tutvunud ja nõustun @link" msgid "data protection terms" msgstr "isikuandmete kaitse põhimõtetega" + +msgid "Highlighted" +msgstr "Esiplaanil" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-fi.po b/modules/oe_theme_helper/translations/oe_theme_helper-fi.po index 4362a93e2..36e6ef295 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-fi.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-fi.po @@ -521,3 +521,6 @@ msgstr "Olen lukenut @link ja hyväksyn sen ehdot" msgid "data protection terms" msgstr "tietosuojaselosteen" + +msgid "Highlighted" +msgstr "Valokeilassa" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-fr.po b/modules/oe_theme_helper/translations/oe_theme_helper-fr.po index 5255d2442..32d0d8cda 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-fr.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-fr.po @@ -521,3 +521,6 @@ msgstr "J'ai lu et j'accepte les @link" msgid "data protection terms" msgstr "conditions relatives à la protection des données" + +msgid "Highlighted" +msgstr "Mis en évidence" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-ga.po b/modules/oe_theme_helper/translations/oe_theme_helper-ga.po index bc46f5098..78e9a2f52 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-ga.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-ga.po @@ -521,3 +521,6 @@ msgstr "Tá na @link léite agam agus glacaim leo" msgid "data protection terms" msgstr "téarmaí cosanta sonraí" + +msgid "Highlighted" +msgstr "Aibhsithe" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-hr.po b/modules/oe_theme_helper/translations/oe_theme_helper-hr.po index beb76766a..79fc0b7b0 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-hr.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-hr.po @@ -521,3 +521,6 @@ msgstr "Pročitao sam i prihvaćam @link" msgid "data protection terms" msgstr "uvjete zaštite podataka" + +msgid "Highlighted" +msgstr "Istaknuto" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-hu.po b/modules/oe_theme_helper/translations/oe_theme_helper-hu.po index 09f909bd7..51075f750 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-hu.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-hu.po @@ -521,3 +521,6 @@ msgstr "Elolvastam az @link és egyetértek vele" msgid "data protection terms" msgstr "adatvédelmi nyilatkozatot," + +msgid "Highlighted" +msgstr "Előtérben" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-it.po b/modules/oe_theme_helper/translations/oe_theme_helper-it.po index bb41eefc2..7722b72fe 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-it.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-it.po @@ -521,3 +521,6 @@ msgstr "Ho letto e accetto le @link" msgid "data protection terms" msgstr "condizioni relative alla protezione dei dati" + +msgid "Highlighted" +msgstr "Evidenziato" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-lt.po b/modules/oe_theme_helper/translations/oe_theme_helper-lt.po index 696449b01..2fa2359e2 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-lt.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-lt.po @@ -521,3 +521,6 @@ msgstr "@link perskaičiau ir su jomis sutinku" msgid "data protection terms" msgstr "Duomenų apsaugos sąlygas" + +msgid "Highlighted" +msgstr "Paryškinta" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-lv.po b/modules/oe_theme_helper/translations/oe_theme_helper-lv.po index b77b8c561..ccefac9e1 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-lv.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-lv.po @@ -521,3 +521,6 @@ msgstr "Esmu izlasījis @link un tiem piekrītu" msgid "data protection terms" msgstr "datu aizsardzības noteikumus" + +msgid "Highlighted" +msgstr "Aktuāli" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-mt.po b/modules/oe_theme_helper/translations/oe_theme_helper-mt.po index c4a25cb61..2c08a8328 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-mt.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-mt.po @@ -521,3 +521,6 @@ msgstr "Qrajt u naqbel @link" msgid "data protection terms" msgstr "mat-termini tal-protezzjoni tad-data" + +msgid "Highlighted" +msgstr "Enfasizzat" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-nl.po b/modules/oe_theme_helper/translations/oe_theme_helper-nl.po index e2fa2e24a..3bd15a013 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-nl.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-nl.po @@ -521,3 +521,6 @@ msgstr "Ik heb de @link gelezen en ga ermee akkoord" msgid "data protection terms" msgstr "privacyverklaring" + +msgid "Highlighted" +msgstr "Actueel" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-pl.po b/modules/oe_theme_helper/translations/oe_theme_helper-pl.po index 8162288d7..460a8d7ed 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-pl.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-pl.po @@ -521,3 +521,6 @@ msgstr "Przeczytałem(-am) i akceptuję @link" msgid "data protection terms" msgstr "warunki ochrony danych" + +msgid "Highlighted" +msgstr "Na pierwszym planie" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-pt-pt.po b/modules/oe_theme_helper/translations/oe_theme_helper-pt-pt.po index 118acb2cb..768fe5e8d 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-pt-pt.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-pt-pt.po @@ -521,3 +521,6 @@ msgstr "Li e concordo com as @link" msgid "data protection terms" msgstr "condições aplicáveis em matéria de proteção de dados" + +msgid "Highlighted" +msgstr "Em destaque" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-ro.po b/modules/oe_theme_helper/translations/oe_theme_helper-ro.po index 952c21e4d..f47484f64 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-ro.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-ro.po @@ -521,3 +521,6 @@ msgstr "Am citit și sunt de acord cu @link" msgid "data protection terms" msgstr "prevederile referitoare la protecția datelor" + +msgid "Highlighted" +msgstr "În prim-plan" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-sk.po b/modules/oe_theme_helper/translations/oe_theme_helper-sk.po index 42eb7ce1b..9af6f36fa 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-sk.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-sk.po @@ -521,3 +521,6 @@ msgstr "Prečítal/a som si podmienky @link a súhlasím s nimi" msgid "data protection terms" msgstr "ochrany údajov" + +msgid "Highlighted" +msgstr "Hlavné témy" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-sl.po b/modules/oe_theme_helper/translations/oe_theme_helper-sl.po index 4220af890..5a0bd12fa 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-sl.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-sl.po @@ -521,3 +521,6 @@ msgstr "Prebral/-a sem pogoje o @link in se strinjam z njimi" msgid "data protection terms" msgstr "varstvu podatkov" + +msgid "Highlighted" +msgstr "Izpostavljeno" diff --git a/modules/oe_theme_helper/translations/oe_theme_helper-sv.po b/modules/oe_theme_helper/translations/oe_theme_helper-sv.po index 708ca5a22..463ef5f4f 100644 --- a/modules/oe_theme_helper/translations/oe_theme_helper-sv.po +++ b/modules/oe_theme_helper/translations/oe_theme_helper-sv.po @@ -521,3 +521,6 @@ msgstr "Jag har läst och godkänner villkoren för @link" msgid "data protection terms" msgstr "skydd av personuppgifter" + +msgid "Highlighted" +msgstr "I fokus" diff --git a/package.json b/package.json index 55257a0dd..9a8f16fc1 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "@ecl/twig-component-inpage-navigation": "3.1.2", "@ecl/twig-component-language-list": "3.1.2", "@ecl/twig-component-link": "3.1.2", + "@ecl/twig-component-label": "3.1.2", "@ecl/twig-component-media-container": "3.1.2", "@ecl/twig-component-menu": "3.1.2", "@ecl/twig-component-message": "3.1.2", diff --git a/templates/content/node--oe-call-proposals--teaser.html.twig b/templates/content/node--oe-call-proposals--teaser.html.twig index cafe57937..9c4d49def 100644 --- a/templates/content/node--oe-call-proposals--teaser.html.twig +++ b/templates/content/node--oe-call-proposals--teaser.html.twig @@ -4,18 +4,17 @@ * Teaser template implementation for "Call for proposals" content type. */ #} -{% set meta = [ - content.extra_field_oe_call_proposals_label_status|field_value, -] %} {% set additional_information = [ content.group_details, ] %} +{# Add cache info from status field. #} +{% set bubble_cache = content.extra_field_oe_call_proposals_label_status|render %} {% block content %} {{ pattern('list_item', { 'variant': 'default', 'url': url, 'title': content.extra_field_oe_theme_helper_short_title_with_fallback|field_value, - 'meta': meta, 'additional_information': additional_information, + 'badges': badges, }) }} {% endblock %} diff --git a/templates/content/node--oe-call-tenders--teaser.html.twig b/templates/content/node--oe-call-tenders--teaser.html.twig index b138d1858..86ed5fe30 100644 --- a/templates/content/node--oe-call-tenders--teaser.html.twig +++ b/templates/content/node--oe-call-tenders--teaser.html.twig @@ -4,18 +4,17 @@ * Teaser template implementtion for "Call for tenders" content type. */ #} -{% set meta = [ - content.extra_field_oe_call_tenders_label_status|field_value, -] %} {% set additional_information = [ content.group_details, ] %} +{# Add cache info from status field. #} +{% set bubble_cache = content.extra_field_oe_call_tenders_label_status|render %} {% block content %} {{ pattern('list_item', { 'variant': 'default', 'url': url, 'title': content.extra_field_oe_theme_helper_short_title_with_fallback|field_value, - 'meta': meta, 'additional_information': additional_information, + 'badges': badges, }) }} {% endblock %} diff --git a/templates/content/node--oe-consultation--teaser.html.twig b/templates/content/node--oe-consultation--teaser.html.twig index 71800eb58..e745f26ad 100644 --- a/templates/content/node--oe-consultation--teaser.html.twig +++ b/templates/content/node--oe-consultation--teaser.html.twig @@ -7,14 +7,14 @@ {% set additional_information = [ content.group_details, ] %} +{# Add cache info from status field. #} +{% set bubble_cache = content.extra_field_oe_consultation_label_status|render %} {% block content %} {{ pattern('list_item', { 'variant': 'default', 'url': url, 'title': content.extra_field_oe_theme_helper_short_title_with_fallback|field_value, - 'meta': [ - content.extra_field_oe_consultation_label_status|field_value, - ], - 'additional_information': additional_information + 'additional_information': additional_information, + 'badges': badges, }) }} {% endblock %} diff --git a/templates/content/node--oe-event--teaser.html.twig b/templates/content/node--oe-event--teaser.html.twig index 70f5766e7..1308aa825 100644 --- a/templates/content/node--oe-event--teaser.html.twig +++ b/templates/content/node--oe-event--teaser.html.twig @@ -9,7 +9,6 @@ {% if status == 'past' or status == 'cancelled' or status == 'ongoing' %} {% set variant = 'date_' ~ status %} {% endif %} -{% set meta = content.extra_field_oe_theme_content_event_teaser_meta|field_value %} {% set detail = content.extra_field_oe_theme_content_event_teaser_details %} {% set additional_information = [] %} {% block content %} @@ -18,8 +17,9 @@ 'url': url, 'title': content.extra_field_oe_theme_helper_short_title_with_fallback|field_value, 'date': pattern_date, - 'meta': meta, + 'meta': content.extra_field_oe_theme_content_event_teaser_meta|field_value, 'detail': detail, 'additional_information': additional_information, + 'badges': badges, }) }} {% endblock %} diff --git a/templates/content/node--oe-news--teaser.html.twig b/templates/content/node--oe-news--teaser.html.twig index 73f962903..c0225d427 100644 --- a/templates/content/node--oe-news--teaser.html.twig +++ b/templates/content/node--oe-news--teaser.html.twig @@ -24,6 +24,7 @@ 'detail': detail, 'image': image_url ? { 'src': image_url }, 'additional_information': additional_information, + 'badges': badges, }) }} {% endblock %} {% endspaceless %} diff --git a/templates/content/node--oe-organisation--teaser.html.twig b/templates/content/node--oe-organisation--teaser.html.twig index a921d98f0..a259c8dc0 100644 --- a/templates/content/node--oe-organisation--teaser.html.twig +++ b/templates/content/node--oe-organisation--teaser.html.twig @@ -19,6 +19,7 @@ 'title': content.extra_field_oe_theme_helper_short_title_with_fallback|field_value, 'detail': content.oe_teaser|field_value, 'additional_information': additional_information, - 'image': image_url ? { 'src': image_url } + 'image': image_url ? { 'src': image_url }, + 'badges': badges, }) }} {% endblock %} diff --git a/templates/content/node--oe-page--teaser.html.twig b/templates/content/node--oe-page--teaser.html.twig index 64023b076..9f11e6809 100644 --- a/templates/content/node--oe-page--teaser.html.twig +++ b/templates/content/node--oe-page--teaser.html.twig @@ -10,6 +10,7 @@ 'url': url, 'title': content.extra_field_oe_theme_helper_short_title_with_fallback|field_value, 'detail': content.oe_teaser|field_value, - 'additional_information': additional_information|default([]) + 'additional_information': additional_information|default([]), + 'badges': badges, }) }} {% endblock %} diff --git a/templates/content/node--oe-person--teaser.html.twig b/templates/content/node--oe-person--teaser.html.twig index 7616e0156..236dcdb54 100644 --- a/templates/content/node--oe-person--teaser.html.twig +++ b/templates/content/node--oe-person--teaser.html.twig @@ -22,6 +22,7 @@ 'title': label, 'detail': content.oe_teaser|field_value, 'additional_information': additional_information, - 'image': content.portrait_image ? { 'src': content.portrait_image|render } + 'image': content.portrait_image ? { 'src': content.portrait_image|render }, + 'badges': badges, }) }} {% endblock %} diff --git a/templates/content/node--oe-policy--teaser.html.twig b/templates/content/node--oe-policy--teaser.html.twig index 5c2a956d1..fef08e6e5 100644 --- a/templates/content/node--oe-policy--teaser.html.twig +++ b/templates/content/node--oe-policy--teaser.html.twig @@ -10,6 +10,7 @@ 'url': url, 'title': content.extra_field_oe_theme_helper_short_title_with_fallback|field_value, 'detail': content.oe_teaser|field_value, - 'additional_information': additional_information|default([]) + 'additional_information': additional_information|default([]), + 'badges': badges, }) }} {% endblock %} diff --git a/templates/content/node--oe-project--teaser.html.twig b/templates/content/node--oe-project--teaser.html.twig index 32229e2ae..f10bfab05 100644 --- a/templates/content/node--oe-project--teaser.html.twig +++ b/templates/content/node--oe-project--teaser.html.twig @@ -15,6 +15,7 @@ 'title': content.extra_field_oe_theme_helper_short_title_with_fallback|field_value, 'detail': content.oe_teaser|field_value, 'additional_information': additional_information, - 'image': image_url ? { 'src': image_url } + 'image': image_url ? { 'src': image_url }, + 'badges': badges, }) }} {% endblock %} diff --git a/templates/content/node--oe-publication--teaser.html.twig b/templates/content/node--oe-publication--teaser.html.twig index 4077b2f61..1d48f4647 100644 --- a/templates/content/node--oe-publication--teaser.html.twig +++ b/templates/content/node--oe-publication--teaser.html.twig @@ -17,6 +17,7 @@ ], 'detail': content.oe_teaser|field_value, 'image': image_url ? { 'src': image_url }, - 'additional_information': additional_information + 'additional_information': additional_information, + 'badges': badges, }) }} {% endblock %} diff --git a/templates/patterns/featured_item/featured_item.ui_patterns.yml b/templates/patterns/featured_item/featured_item.ui_patterns.yml index 5747e3610..a7f713cca 100644 --- a/templates/patterns/featured_item/featured_item.ui_patterns.yml +++ b/templates/patterns/featured_item/featured_item.ui_patterns.yml @@ -58,3 +58,12 @@ featured_item: preview: href: "http://example.com" label: "Read more" + badges: + type: array + label: "Badges" + description: "Adds different badges to the item." + preview: + - label: "Highlighted" + variant: "highlight" + - label: "Status: Open" + variant: "high" diff --git a/templates/patterns/featured_item/pattern-featured-item.html.twig b/templates/patterns/featured_item/pattern-featured-item.html.twig index 7aea65ce6..8440cb981 100644 --- a/templates/patterns/featured_item/pattern-featured-item.html.twig +++ b/templates/patterns/featured_item/pattern-featured-item.html.twig @@ -55,7 +55,8 @@ 'type': "standalone" }, 'infos': _footer_items, - 'image': image + 'image': image, + 'labels': badges, } %} {% include '@ecl-twig/card' with { diff --git a/templates/patterns/file_teaser/file_teaser.ui_patterns.yml b/templates/patterns/file_teaser/file_teaser.ui_patterns.yml index a7f4b7d73..cd506658e 100644 --- a/templates/patterns/file_teaser/file_teaser.ui_patterns.yml +++ b/templates/patterns/file_teaser/file_teaser.ui_patterns.yml @@ -98,3 +98,10 @@ file_teaser: description: "Used to trim the length of the 'Teaser' fields (optional)." preview: 10 escape: false + badges: + type: array + label: "Badges" + description: "Adds different badges to the file. Warning: Due to ECL constraints, only the first item will be taken into account." + preview: + - label: "Highlighted" + variant: "highlight" diff --git a/templates/patterns/file_teaser/pattern-file-teaser.html.twig b/templates/patterns/file_teaser/pattern-file-teaser.html.twig index ac1c17a7e..fb9ec5e5a 100644 --- a/templates/patterns/file_teaser/pattern-file-teaser.html.twig +++ b/templates/patterns/file_teaser/pattern-file-teaser.html.twig @@ -46,6 +46,9 @@ {% if file.size %} {% set _meta = '(' ~ file.size|format_size ~ ' - ' ~ file.extension|upper ~ ')' %} {% endif %} +{% if badges %} + {% set _label = badges|first %} +{% endif %} {% include '@ecl-twig/file' with { 'title': file.title, 'description': teaser|smart_trim(length), @@ -82,4 +85,5 @@ 'detail_meta': _detail_meta, 'variant': 'thumbnail', 'lists': _lists, + 'label': _label, } only %} diff --git a/templates/patterns/list_item/list_item.ui_patterns.yml b/templates/patterns/list_item/list_item.ui_patterns.yml index 542332d60..249500309 100644 --- a/templates/patterns/list_item/list_item.ui_patterns.yml +++ b/templates/patterns/list_item/list_item.ui_patterns.yml @@ -95,3 +95,12 @@ list_item: label: "Icon" description: "An optional icon to be used with the link." preview: "external" + badges: + type: array + label: "Badges" + description: "Adds different badges to the item." + preview: + - label: "Highlighted" + variant: "highlight" + - label: "Status: Open" + variant: "high" diff --git a/templates/patterns/list_item/pattern-list-item--variant-block.html.twig b/templates/patterns/list_item/pattern-list-item--variant-block.html.twig index 9334b066b..4a6786eb4 100644 --- a/templates/patterns/list_item/pattern-list-item--variant-block.html.twig +++ b/templates/patterns/list_item/pattern-list-item--variant-block.html.twig @@ -11,6 +11,7 @@ path: url, type: "standalone" }, - description: detail|smart_trim(length) + description: detail|smart_trim(length), + labels: badges, } } only %} diff --git a/templates/patterns/list_item/pattern-list-item--variant-date.html.twig b/templates/patterns/list_item/pattern-list-item--variant-date.html.twig index 54eb82383..c408b657a 100644 --- a/templates/patterns/list_item/pattern-list-item--variant-date.html.twig +++ b/templates/patterns/list_item/pattern-list-item--variant-date.html.twig @@ -28,8 +28,27 @@ {% endblock %}
<div>This is the detail...
' - array: @@ -983,7 +998,7 @@ 'article.ecl-content-item div.ecl-content-item__image__after': 0 'article > div .ecl-description-list': 0 equals: - 'article.ecl-content-item div.ecl-content-item__meta': "Meta 1 | Meta 2" + 'article.ecl-content-item div.ecl-content-item__meta div.ecl-u-mt-xs': "Meta 1 | Meta 2" 'article.ecl-content-item div.ecl-content-item__title .ecl-link': "Item title" 'article.ecl-content-item div.ecl-content-item__description': '<div>This is the detail...
' - array: @@ -1046,7 +1061,7 @@ 'article.ecl-content-item div.ecl-content-item__image__before': 1 'article.ecl-content-item div.ecl-content-item__image__after': 0 equals: - 'article.ecl-content-item div.ecl-content-item__meta': "Meta 1 | Meta 2" + 'article.ecl-content-item div.ecl-content-item__meta div.ecl-u-mt-xs': "Meta 1 | Meta 2" 'article.ecl-content-item div.ecl-content-item__title .ecl-link': "Item title" 'article.ecl-content-item div.ecl-content-item__description': "Item text" - array: @@ -1070,7 +1085,7 @@ 'article.ecl-content-item div.ecl-content-item__image__before': 0 'article.ecl-content-item div.ecl-content-item__image__after': 1 equals: - 'article.ecl-content-item div.ecl-content-item__meta': "Meta 1 | Meta 2" + 'article.ecl-content-item div.ecl-content-item__meta div.ecl-u-mt-xs': "Meta 1 | Meta 2" 'article.ecl-content-item div.ecl-content-item__title .ecl-link': "Item title" 'article.ecl-content-item div.ecl-content-item__description': "Item text" - array: @@ -1083,6 +1098,11 @@ image: src: "http://via.placeholder.com/300x300" alt: "Alternate text for secondary image" + badges: + - label: "Highlighted" + variant: "highlight" + - label: "Status: Open" + variant: "high" assertions: count: article.ecl-card div.ecl-card__body h1.ecl-card__title a.ecl-link--standalone[href="http://example.com"]: 1 @@ -1090,8 +1110,12 @@ article.ecl-card div.ecl-card__image[style="background-image:url('http://via.placeholder.com/300x300')"]: 1 article.ecl-card div.ecl-card__body div.ecl-card__meta: 0 article.ecl-card div.ecl-card__body div.ecl-card__description: 0 + article.ecl-card div.ecl-card__body ul.ecl-card__label-container: 1 + ul.ecl-card__label-container li.ecl-card__label-item: 2 equals: article.ecl-card div.ecl-card__body h1.ecl-card__title .ecl-link: "Item title" + ul.ecl-card__label-container li.ecl-card__label-item:nth-child(1) span.ecl-label.ecl-label--highlight.ecl-card__label: "Highlighted" + ul.ecl-card__label-container li.ecl-card__label-item:nth-child(2) span.ecl-label.ecl-label--high.ecl-card__label: "Status: Open" - array: '#type': pattern '#id': list_item @@ -1111,6 +1135,7 @@ article.ecl-card div.ecl-card__image[style="background-image:url('http://via.placeholder.com/300x300')"]: 1 article.ecl-card div.ecl-card__body div.ecl-card__meta: 0 article.ecl-card div.ecl-card__body div.ecl-card__description: 1 + article.ecl-card div.ecl-card__body ul.ecl-card__label-container: 0 equals: article.ecl-card div.ecl-card__body h1.ecl-card__title .ecl-link: "Item title" article.ecl-card div.ecl-card__body div.ecl-card__description: "This is a very long description..." @@ -1122,14 +1147,23 @@ title: "Item title" url: "http://example.com" detail: "Item test" + badges: + - label: "Highlighted" + variant: "highlight" + - label: "Status: Open" + variant: "high" assertions: count: 'article.ecl-card div.ecl-card__body h1.ecl-card__title a.ecl-link--standalone[href="http://example.com"]': 1 'article.ecl-card div.ecl-card__image': 0 'article.ecl-card div.ecl-card__body div.ecl-card__meta': 0 + 'article.ecl-card div.ecl-card__body ul.ecl-card__label-container': 1 + 'ul.ecl-card__label-container li.ecl-card__label-item': 2 equals: 'article.ecl-card div.ecl-card__body h1.ecl-card__title .ecl-link': "Item title" 'article.ecl-card div.ecl-card__body div.ecl-card__description': "Item test" + 'ul.ecl-card__label-container li.ecl-card__label-item:nth-child(1) span.ecl-label.ecl-label--highlight.ecl-card__label': "Highlighted" + 'ul.ecl-card__label-container li.ecl-card__label-item:nth-child(2) span.ecl-label.ecl-label--high.ecl-card__label': "Status: Open" - array: '#type': pattern '#id': list_item @@ -1147,13 +1181,22 @@ meta: - "News article" - "6 July 2015" + badges: + - label: "Highlighted" + variant: "highlight" + - label: "Status: Open" + variant: "medium" assertions: count: 'article.ecl-content-item-date div.ecl-content-item-date__title a.ecl-link[href="http://example.com"]': 1 'article.ecl-content-item-date div.ecl-content-item-date__date': 1 'article.ecl-content-item-date div.ecl-content-item-date__date abbr.ecl-date-block__month[title="July"]': 1 + 'span.ecl-label.ecl-label--highlight.ecl-u-mr-xs': 1 + 'span.ecl-label.ecl-label--medium.ecl-u-mr-xs.ecl-u-type-color-black': 1 equals: - 'article.ecl-content-item-date div.ecl-content-item-date__meta': "News article | 6 July 2015" + 'article.ecl-content-item-date div.ecl-content-item-date__meta span.ecl-label.ecl-label--highlight.ecl-u-mr-xs': "Highlighted" + 'article.ecl-content-item-date div.ecl-content-item-date__meta span.ecl-label.ecl-label--medium.ecl-u-mr-xs.ecl-u-type-color-black': "Status: Open" + 'article.ecl-content-item-date div.ecl-content-item-date__meta div.ecl-u-mt-xs': "News article | 6 July 2015" 'article.ecl-content-item-date div.ecl-content-item-date__title .ecl-link': "Item title" 'article.ecl-content-item-date div.ecl-content-item-date__description': "Item text" 'article.ecl-content-item-date div.ecl-content-item-date__date span.ecl-date-block__day': '14' @@ -1195,7 +1238,7 @@ 'div.ecl-content-item__additional_information .ecl-description-list__term': 2 'div.ecl-content-item__additional_information .ecl-description-list__definition': 2 equals: - 'article.ecl-content-item-date div.ecl-content-item-date__meta': "News article | 6 July 2015" + 'article.ecl-content-item-date div.ecl-content-item-date__meta div.ecl-u-mt-xs': "News article | 6 July 2015" 'article.ecl-content-item-date div.ecl-content-item-date__title .ecl-link': "Item title" 'article.ecl-content-item-date div.ecl-content-item-date__description': "Item text" 'article.ecl-content-item-date div.ecl-content-item-date__date span.ecl-date-block__day': '14' @@ -2132,6 +2175,7 @@ 'h1.ecl-card__title': 1 'div.ecl-card__description': 0 'ul.ecl-card__info-container': 0 + 'article.ecl-card div.ecl-card__body ul.ecl-card__label-container': 0 equals: 'h1.ecl-card__title': "Example title" - array: @@ -2150,15 +2194,24 @@ link: href: "https://example.com" label: "Link title" + badges: + - label: "Highlighted" + variant: "highlight" + - label: "Status: Open" + variant: "high" assertions: count: "div.ecl-card__image[style=\"background-image:url('http://via.placeholder.com/120x80')\"]": 1 'h1.ecl-card__title a.ecl-link--standalone[href="https://example.com"]': 1 'a.ecl-button': 0 + 'article.ecl-card div.ecl-card__body ul.ecl-card__label-container': 1 + 'ul.ecl-card__label-container li.ecl-card__label-item': 2 equals: 'div.ecl-card__meta': "Breaking news article | Brussels" 'h1.ecl-card__title a': "Example title" 'div.ecl-card__description': "Example description" + 'ul.ecl-card__label-container li.ecl-card__label-item:nth-child(1) span.ecl-label.ecl-label--highlight.ecl-card__label': "Highlighted" + 'ul.ecl-card__label-container li.ecl-card__label-item:nth-child(2) span.ecl-label.ecl-label--high.ecl-card__label': "Status: Open" - array: '#type': pattern '#id': featured_item @@ -2181,6 +2234,7 @@ "div.ecl-card__image[style=\"background-image:url('http://via.placeholder.com/120x80')\"]": 1 'h1.ecl-card__title a.ecl-link--standalone[href="https://example.com"]': 1 'a.ecl-button': 0 + 'article.ecl-card div.ecl-card__body ul.ecl-card__label-container': 0 equals: 'div.ecl-card__meta': "Breaking news article | Brussels" 'h1.ecl-card__title a': "Example title" @@ -2245,6 +2299,7 @@ assertions: count: "ul.ecl-card__info-container": 1 + 'article.ecl-card div.ecl-card__body ul.ecl-card__label-container': 0 equals: 'li.ecl-card__info-item:nth-child(1)' : '15-16 November 2019, 08:00 AM' 'li.ecl-card__info-item:nth-child(2)' : 'Brussels, Belgium' diff --git a/tests/src/PatternAssertions/FeaturedItemAssert.php b/tests/src/PatternAssertions/FeaturedItemAssert.php index 1d47b7fa5..95aaf2ea5 100644 --- a/tests/src/PatternAssertions/FeaturedItemAssert.php +++ b/tests/src/PatternAssertions/FeaturedItemAssert.php @@ -39,6 +39,9 @@ protected function getAssertions($variant): array { 'footer_items' => [ [$this, 'assertFooterItems'], ], + 'badges' => [ + [$this, 'assertBadges'], + ], ]; } @@ -113,6 +116,29 @@ protected function assertFooterItems($expected_info_items, Crawler $crawler): vo } } + /** + * Asserts the badge(s) of a card. + * + * @param array|null $expected_badges + * The expected badges. + * @param \Symfony\Component\DomCrawler\Crawler $crawler + * The DomCrawler where to check the element. + */ + protected function assertBadges(?array $expected_badges, Crawler $crawler): void { + $base_selector = 'article.ecl-card div.ecl-card__body ul.ecl-card__label-container li.ecl-card__label-item'; + if (is_null($expected_badges)) { + $this->assertElementNotExists('span.ecl-label', $crawler); + return; + } + foreach ($expected_badges as $badge) { + if (!isset($badge['label']) || !isset($badge['variant'])) { + continue; + } + $selector = $base_selector . ' span.ecl-label.ecl-label--' . $badge['variant'] . '.ecl-u-mr-xs'; + self::assertStringContainsString($badge['label'], $crawler->filter($selector)->text()); + } + } + /** * {@inheritdoc} * diff --git a/tests/src/PatternAssertions/FileTeaserAssert.php b/tests/src/PatternAssertions/FileTeaserAssert.php index 8ec2bef0c..08df5f8e8 100644 --- a/tests/src/PatternAssertions/FileTeaserAssert.php +++ b/tests/src/PatternAssertions/FileTeaserAssert.php @@ -30,6 +30,10 @@ protected function getAssertions($variant): array { $assertions['lists'] = [ [$this, 'assertLists'], ]; + $assertions['badge'] = [ + [$this, 'assertBadge'], + 'div.ecl-file--thumbnail div.ecl-file__container div.ecl-file__detail div.ecl-file__detail-info div.ecl-file__label', + ]; return $assertions; } @@ -114,4 +118,24 @@ protected function assertTranslation(array $expected_file, Crawler $crawler): vo $this->assertElementAttribute($expected_file['url'], 'a.ecl-file__translation-download', 'href', $crawler); } + /** + * Asserts the badge of the file. + * + * @param array|null $badge + * The expected badge. + * @param string $selector + * The CSS selector to find the badge. + * @param \Symfony\Component\DomCrawler\Crawler $crawler + * The DomCrawler where to check the element. + */ + protected function assertBadge(?array $badge, string $selector, Crawler $crawler): void { + if (is_null($badge)) { + $this->assertElementNotExists($selector, $crawler); + return; + } + $this->assertElementExists($selector, $crawler); + $selector = $selector . ' span.ecl-label.ecl-label--' . $badge['variant']; + self::assertStringContainsString($badge['label'], $crawler->filter($selector)->text()); + } + } diff --git a/tests/src/PatternAssertions/ListItemAssert.php b/tests/src/PatternAssertions/ListItemAssert.php index 2a5fa0164..726343fc8 100644 --- a/tests/src/PatternAssertions/ListItemAssert.php +++ b/tests/src/PatternAssertions/ListItemAssert.php @@ -49,7 +49,7 @@ protected function getAssertions($variant): array { ], 'meta' => [ [$this, 'assertElementText'], - $base_selector . '__meta', + $base_selector . '__meta div.ecl-u-mt-xs', ], 'date' => [ [$this, 'assertDate'], @@ -69,6 +69,10 @@ protected function getAssertions($variant): array { 'icon' => [ [$this, 'assertIcon'], ], + 'badges' => [ + [$this, 'assertBadges'], + $variant, + ], ]; } @@ -274,7 +278,32 @@ protected function assertIcon($expected, Crawler $crawler): void { return; } $icon = $crawler->filter($icon_selector); - self::assertContains($expected, $icon->attr('xlink:href')); + self::assertStringContainsString($expected, $icon->attr('xlink:href')); + } + + /** + * Asserts the badge(s) of the list item link. + * + * @param array|null $expected_badges + * The expected badges. + * @param string $variant + * The variant of the pattern being checked. + * @param \Symfony\Component\DomCrawler\Crawler $crawler + * The DomCrawler where to check the element. + */ + protected function assertBadges(?array $expected_badges, string $variant, Crawler $crawler): void { + $base_selector = 'div' . $this->getBaseItemClass($variant) . '__meta'; + if (is_null($expected_badges)) { + $this->assertElementNotExists('span.ecl-label', $crawler); + return; + } + foreach ($expected_badges as $badge) { + if (!isset($badge['label']) || !isset($badge['variant'])) { + continue; + } + $selector = $base_selector . ' span.ecl-label.ecl-label--' . $badge['variant'] . '.ecl-u-mr-xs'; + self::assertStringContainsString($badge['label'], $crawler->filter($selector)->text()); + } } /**