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 %}
{% block meta %} - {% if meta is not empty %} -
{{ meta|filter_empty|safe_join(" | ") }}
+ {% if meta is not empty or badges is not empty %} +
+ {% if badges is iterable %} + {% set extra_classes = 'ecl-u-mr-xs' %} + {% for _badge in badges %} + {% if _badge.variant != 'highlight' %} + {% set _extra_classes = extra_classes ~ ' ecl-u-type-color-black' %} + {% endif %} + {% include '@ecl-twig/label' with { + 'label': _badge.label|t, + 'variant': _badge.variant, + 'extra_classes': _extra_classes|default(extra_classes), + } only %} + {% endfor %} + {% endif %} + {% if meta is not empty %} +
+ {{ meta|filter_empty|safe_join(" | ") }} +
+ {% endif %} +
{% endif %} {% endblock %} {% block title %} diff --git a/templates/patterns/list_item/pattern-list-item--variant-highlight.html.twig b/templates/patterns/list_item/pattern-list-item--variant-highlight.html.twig index ab5dea3ea..353ed236c 100644 --- a/templates/patterns/list_item/pattern-list-item--variant-highlight.html.twig +++ b/templates/patterns/list_item/pattern-list-item--variant-highlight.html.twig @@ -13,5 +13,6 @@ }, image: image, description: detail|smart_trim(length), + labels: badges, } } only %} diff --git a/templates/patterns/list_item/pattern-list-item.html.twig b/templates/patterns/list_item/pattern-list-item.html.twig index 1770b5659..77ee70f94 100644 --- a/templates/patterns/list_item/pattern-list-item.html.twig +++ b/templates/patterns/list_item/pattern-list-item.html.twig @@ -42,8 +42,27 @@ {% endif %}
{% block meta %} - {% if meta is not empty %} -
{{ meta|filter_empty|safe_join(" | ") }}
+ {% if meta is not empty or badges is not empty %} +
+ {% if badges is iterable %} + {% set extra_classes = 'ecl-u-mr-xs' %} + {% for _badge in badges %} + {% if _badge.variant != 'highlight' %} + {% set _extra_classes = extra_classes ~ ' ecl-u-type-color-black' %} + {% endif %} + {% include '@ecl-twig/label' with { + 'label': _badge.label|t, + 'variant': _badge.variant, + 'extra_classes': _extra_classes|default(extra_classes), + } only %} + {% endfor %} + {% endif %} + {% if meta is not empty %} +
+ {{ meta|filter_empty|safe_join(" | ") }} +
+ {% endif %} +
{% endif %} {% endblock %} {% block title %} diff --git a/tests/src/Kernel/CallForProposalsRenderTest.php b/tests/src/Kernel/CallForProposalsRenderTest.php index 6beba4a13..0d80bc468 100644 --- a/tests/src/Kernel/CallForProposalsRenderTest.php +++ b/tests/src/Kernel/CallForProposalsRenderTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Datetime\DrupalDateTime; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; use Drupal\node\Entity\Node; +use Drupal\node\NodeInterface; use Drupal\Tests\oe_theme\PatternAssertions\ListItemAssert; use Drupal\Tests\oe_theme\PatternAssertions\FieldListAssert; use Drupal\Tests\oe_theme\PatternAssertions\PatternAssertState; @@ -92,6 +93,7 @@ public function testTeaser(): void { 'oe_reference_code' => 'Call for proposals reference', 'uid' => 0, 'status' => 1, + 'sticky' => NodeInterface::NOT_STICKY, ]; $node = Node::create($values); $node->save(); @@ -104,7 +106,12 @@ public function testTeaser(): void { $deadline_date->setTimeZone(new \DateTimeZone('Australia/Sydney')); $expected_values = [ 'title' => 'Test Call for proposals node', - 'meta' => 'Call status: Open', + 'badges' => [ + [ + 'label' => 'Call status: Open', + 'variant' => 'high', + ], + ], 'image' => NULL, 'additional_information' => [ new PatternAssertState(new FieldListAssert(), [ @@ -132,7 +139,7 @@ public function testTeaser(): void { $assert->assertPattern($expected_values, $html); $crawler = new Crawler($html); - $actual = $crawler->filter('span.call-status.ecl-label.ecl-label--high.ecl-u-type-color-black'); + $actual = $crawler->filter('span.ecl-label.ecl-label--high.ecl-u-type-color-black'); $this->assertCount(1, $actual); // Test short title fallback. @@ -176,15 +183,25 @@ public function testTeaser(): void { ]; $assert->assertPattern($expected_values, $html); - // Check status Closed label and background. + // Check status Closed and highlighted labels and background. $deadline_date->modify('- 4 days'); $node->set('oe_call_proposals_deadline', [ $deadline_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), ]); + $node->set('sticky', NodeInterface::STICKY); $node->set('oe_call_proposals_model', 'multiple_cut_off')->save(); $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); - $expected_values['meta'] = 'Call status: Closed'; + $expected_values['badges'] = [ + [ + 'label' => 'Call status: Closed', + 'variant' => 'low', + ], + [ + 'label' => 'Highlighted', + 'variant' => 'highlight', + ], + ]; $expected_values['additional_information'] = [ new PatternAssertState(new FieldListAssert(), [ 'items' => [ @@ -210,7 +227,7 @@ public function testTeaser(): void { $assert->assertPattern($expected_values, $html); $crawler = new Crawler($html); - $actual = $crawler->filter('span.call-status.ecl-label.ecl-label--low.ecl-u-type-color-black'); + $actual = $crawler->filter('span.ecl-label.ecl-label--low.ecl-u-type-color-black'); $this->assertCount(1, $actual); // Check status Upcoming label and background. @@ -223,7 +240,10 @@ public function testTeaser(): void { $node->set('oe_call_proposals_opening_date', $opening_date->format('Y-m-d'))->save(); $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); - $expected_values['meta'] = 'Call status: Upcoming'; + $expected_values['badges'][0] = [ + 'label' => 'Call status: Upcoming', + 'variant' => 'medium', + ]; $expected_values['additional_information'] = [ new PatternAssertState(new FieldListAssert(), [ 'items' => [ @@ -249,7 +269,7 @@ public function testTeaser(): void { $assert->assertPattern($expected_values, $html); $crawler = new Crawler($html); - $actual = $crawler->filter('span.call-status.ecl-label.ecl-label--medium.ecl-u-type-color-black'); + $actual = $crawler->filter('span.ecl-label.ecl-label--medium.ecl-u-type-color-black'); $this->assertCount(1, $actual); // Check status N/A. @@ -262,7 +282,7 @@ public function testTeaser(): void { $node->set('oe_call_proposals_model', 'permanent')->save(); $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); - $expected_values['meta'] = ''; + $expected_values['badges'][0] = []; $expected_values['additional_information'] = [ new PatternAssertState(new FieldListAssert(), [ 'items' => [ diff --git a/tests/src/Kernel/CallForTendersRenderTest.php b/tests/src/Kernel/CallForTendersRenderTest.php index 14a143d3f..a147a5387 100644 --- a/tests/src/Kernel/CallForTendersRenderTest.php +++ b/tests/src/Kernel/CallForTendersRenderTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Datetime\DrupalDateTime; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; use Drupal\node\Entity\Node; +use Drupal\node\NodeInterface; use Drupal\Tests\oe_theme\PatternAssertions\ListItemAssert; use Drupal\Tests\oe_theme\PatternAssertions\FieldListAssert; use Drupal\Tests\oe_theme\PatternAssertions\PatternAssertState; @@ -110,7 +111,12 @@ public function testTeaser(): void { $deadline_date->setTimeZone(new \DateTimeZone('Australia/Sydney')); $expected_values = [ 'title' => 'Test Call for tenders node', - 'meta' => 'Call status: Open', + 'badges' => [ + [ + 'label' => 'Call status: Open', + 'variant' => 'high', + ], + ], 'image' => NULL, 'additional_information' => [ new PatternAssertState(new FieldListAssert(), [ @@ -135,11 +141,12 @@ public function testTeaser(): void { $assert->assertPattern($expected_values, $html); $crawler = new Crawler($html); - $actual = $crawler->filter('span.call-status.ecl-label.ecl-label--high.ecl-u-type-color-black'); + $actual = $crawler->filter('span.ecl-label.ecl-label--high.ecl-u-type-color-black'); $this->assertCount(1, $actual); // Test short title fallback. - $node->set('oe_content_short_title', 'CFT short title')->save(); + $node->set('oe_content_short_title', 'CFT short title'); + $node->set('sticky', NodeInterface::STICKY)->save(); $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); $expected_values['title'] = 'CFT short title'; @@ -170,12 +177,21 @@ public function testTeaser(): void { ]; $assert->assertPattern($expected_values, $html); - // Check status Closed label and background. + // Check status Closed and highlighted labels and background. $deadline_date = (clone $static_time)->modify('- 2 days'); $node->set('oe_call_tenders_deadline', $deadline_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT))->save(); $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); - $expected_values['meta'] = 'Call status: Closed'; + $expected_values['badges'] = [ + [ + 'label' => 'Call status: Closed', + 'variant' => 'low', + ], + [ + 'label' => 'Highlighted', + 'variant' => 'highlight', + ], + ]; $deadline_date->setTimeZone(new \DateTimeZone('Australia/Sydney')); $expected_values['additional_information'] = [ new PatternAssertState(new FieldListAssert(), [ @@ -199,7 +215,7 @@ public function testTeaser(): void { $assert->assertPattern($expected_values, $html); $crawler = new Crawler($html); - $actual = $crawler->filter('span.call-status.ecl-label.ecl-label--low.ecl-u-type-color-black'); + $actual = $crawler->filter('span.ecl-label.ecl-label--low.ecl-u-type-color-black'); $this->assertCount(1, $actual); // Check Deadline date is striked when Call for tenders is closed. @@ -214,7 +230,10 @@ public function testTeaser(): void { $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); $deadline_date->setTimeZone(new \DateTimeZone('Australia/Sydney')); - $expected_values['meta'] = 'Call status: Upcoming'; + $expected_values['badges'][0] = [ + 'label' => 'Call status: Upcoming', + 'variant' => 'medium', + ]; $expected_values['additional_information'] = [ new PatternAssertState(new FieldListAssert(), [ 'items' => [ @@ -237,7 +256,7 @@ public function testTeaser(): void { $assert->assertPattern($expected_values, $html); $crawler = new Crawler($html); - $actual = $crawler->filter('span.call-status.ecl-label.ecl-label--medium.ecl-u-type-color-black'); + $actual = $crawler->filter('span.ecl-label.ecl-label--medium.ecl-u-type-color-black'); $this->assertCount(1, $actual); // Check status N/A. @@ -251,7 +270,7 @@ public function testTeaser(): void { $html = $this->renderRoot($build); $deadline_date->setTimeZone(new \DateTimeZone('Australia/Sydney')); - $expected_values['meta'] = ''; + $expected_values['badges'][0] = []; $expected_values['additional_information'] = [ new PatternAssertState(new FieldListAssert(), [ 'items' => [ diff --git a/tests/src/Kernel/ConsultationRenderTest.php b/tests/src/Kernel/ConsultationRenderTest.php index ce3ed8222..aa520f777 100644 --- a/tests/src/Kernel/ConsultationRenderTest.php +++ b/tests/src/Kernel/ConsultationRenderTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Datetime\DrupalDateTime; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; use Drupal\node\Entity\Node; +use Drupal\node\NodeInterface; use Drupal\Tests\oe_theme\PatternAssertions\ListItemAssert; use Drupal\Tests\oe_theme\PatternAssertions\FieldListAssert; use Drupal\Tests\oe_theme\PatternAssertions\PatternAssertState; @@ -98,7 +99,12 @@ public function testTeaser(): void { $deadline_date->setTimeZone(new \DateTimeZone('Australia/Sydney')); $expected_values = [ 'title' => 'Test Consultation node', - 'meta' => 'Status: Open', + 'badges' => [ + [ + 'label' => 'Status: Open', + 'variant' => 'high', + ], + ], 'image' => NULL, 'additional_information' => [ new PatternAssertState(new FieldListAssert(), [ @@ -118,24 +124,34 @@ public function testTeaser(): void { $assert->assertPattern($expected_values, $html); $crawler = new Crawler($html); - $actual = $crawler->filter('span.call-status.ecl-label.ecl-label--high.ecl-u-type-color-black'); + $actual = $crawler->filter('span.ecl-label.ecl-label--high.ecl-u-type-color-black'); $this->assertCount(1, $actual); // Test short title fallback. - $node->set('oe_content_short_title', 'Consultation short title')->save(); + $node->set('oe_content_short_title', 'Consultation short title'); + $node->set('sticky', NodeInterface::STICKY)->save(); $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); $expected_values['title'] = 'Consultation short title'; $assert->assertPattern($expected_values, $html); - // Check status Closed label and background. + // Check status Closed and highlighted label and background. $deadline_date->modify('- 4 days'); $node->set('oe_consultation_deadline', [ $deadline_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), ])->save(); $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); - $expected_values['meta'] = 'Status: Closed'; + $expected_values['badges'] = [ + [ + 'label' => 'Status: Closed', + 'variant' => 'low', + ], + [ + 'label' => 'Highlighted', + 'variant' => 'highlight', + ], + ]; $expected_values['additional_information'] = [ new PatternAssertState(new FieldListAssert(), [ 'items' => [ @@ -152,7 +168,7 @@ public function testTeaser(): void { $assert->assertPattern($expected_values, $html); $crawler = new Crawler($html); - $actual = $crawler->filter('span.call-status.ecl-label.ecl-label--low.ecl-u-type-color-black'); + $actual = $crawler->filter('span.ecl-label.ecl-label--low.ecl-u-type-color-black'); $this->assertCount(1, $actual); // Check status Upcoming label and background. @@ -164,7 +180,10 @@ public function testTeaser(): void { $node->set('oe_consultation_opening_date', $opening_date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT))->save(); $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); - $expected_values['meta'] = 'Status: Upcoming'; + $expected_values['badges'][0] = [ + 'label' => 'Status: Upcoming', + 'variant' => 'medium', + ]; $expected_values['additional_information'] = [ new PatternAssertState(new FieldListAssert(), [ 'items' => [ @@ -181,7 +200,7 @@ public function testTeaser(): void { $assert->assertPattern($expected_values, $html); $crawler = new Crawler($html); - $actual = $crawler->filter('span.call-status.ecl-label.ecl-label--medium.ecl-u-type-color-black'); + $actual = $crawler->filter('span.ecl-label.ecl-label--medium.ecl-u-type-color-black'); $this->assertCount(1, $actual); } diff --git a/tests/src/Kernel/EventRenderTest.php b/tests/src/Kernel/EventRenderTest.php index c743cc07e..043ae0050 100644 --- a/tests/src/Kernel/EventRenderTest.php +++ b/tests/src/Kernel/EventRenderTest.php @@ -8,6 +8,7 @@ use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; use Drupal\media\Entity\Media; use Drupal\node\Entity\Node; +use Drupal\node\NodeInterface; use Drupal\oe_content_entity_venue\Entity\Venue; use Drupal\Tests\oe_theme\PatternAssertions\IconsTextAssert; use Drupal\Tests\oe_theme\PatternAssertions\ListItemAssert; @@ -168,6 +169,7 @@ public function testEventTeaser(): void { ], ], ]), + 'badges' => NULL, 'meta' => 'Competitions and award ceremonies', 'image' => NULL, 'date' => [ @@ -180,11 +182,18 @@ public function testEventTeaser(): void { $assert->assertPattern($expected_values, $html); $assert->assertVariant('date', $html); - // Test short title fallback. - $node->set('oe_content_short_title', 'Event short title')->save(); + // Test short title fallback and highlighted label. + $node->set('oe_content_short_title', 'Event short title'); + $node->set('sticky', NodeInterface::STICKY)->save(); $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); $expected_values['title'] = 'Event short title'; + $expected_values['badges'] = [ + [ + 'label' => 'Highlighted', + 'variant' => 'highlight', + ], + ]; $assert->assertPattern($expected_values, $html); // Set full address in venue. @@ -249,6 +258,7 @@ public function testEventTeaser(): void { $build = $this->nodeViewBuilder->view($node, 'teaser', 'bg'); $html = $this->renderRoot($build); $expected_values['title'] = 'заглавието на моя възел'; + $expected_values['badges'] = NULL; $expected_values['meta'] = 'Конкурси и церемонии по награждаване | Cancelled'; $expected_values['url'] = '/bg/node/1'; $expected_values['date']['month_name'] = 'Ян.'; diff --git a/tests/src/Kernel/NewsRenderTest.php b/tests/src/Kernel/NewsRenderTest.php index 1ba38a043..deced21fb 100644 --- a/tests/src/Kernel/NewsRenderTest.php +++ b/tests/src/Kernel/NewsRenderTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\oe_theme\Kernel; use Drupal\media\Entity\Media; +use Drupal\node\NodeInterface; use Drupal\Tests\oe_theme\PatternAssertions\ListItemAssert; use Drupal\Tests\user\Traits\UserCreationTrait; @@ -70,6 +71,7 @@ public function testNewsTeaser(): void { $expected_values = [ 'title' => 'Test news node', + 'badges' => NULL, 'url' => '/en/node/1', 'description' => 'Teaser', 'meta' => 'News article | 2 April 2019', @@ -81,11 +83,18 @@ public function testNewsTeaser(): void { $assert->assertPattern($expected_values, $html); $assert->assertVariant('thumbnail_primary', $html); - // Test short title fallback. - $node->set('oe_content_short_title', 'News short title')->save(); + // Test short title fallback and highlighted label. + $node->set('oe_content_short_title', 'News short title'); + $node->set('sticky', NodeInterface::STICKY)->save(); $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); $expected_values['title'] = 'News short title'; + $expected_values['badges'] = [ + [ + 'label' => 'Highlighted', + 'variant' => 'highlight', + ], + ]; $assert->assertPattern($expected_values, $html); // Unpublish the media and assert it is not rendered anymore. @@ -129,6 +138,12 @@ public function testNewsTeaser(): void { 'title' => 'News short title', 'url' => '/en/node/1', 'description' => 'Teaser', + 'badges' => [ + [ + 'label' => 'Highlighted', + 'variant' => 'highlight', + ], + ], 'meta' => 'Press release | 2 April 2019', 'image' => [ 'src' => 'example_1.jpeg', diff --git a/tests/src/Kernel/OrganisationRenderTest.php b/tests/src/Kernel/OrganisationRenderTest.php index 9acc75a7b..6ffa83687 100644 --- a/tests/src/Kernel/OrganisationRenderTest.php +++ b/tests/src/Kernel/OrganisationRenderTest.php @@ -6,6 +6,7 @@ use Drupal\media\Entity\Media; use Drupal\node\Entity\Node; +use Drupal\node\NodeInterface; use Drupal\Tests\oe_theme\PatternAssertions\FieldListAssert; use Drupal\Tests\oe_theme\PatternAssertions\ListItemAssert; use Drupal\Tests\oe_theme\PatternAssertions\PatternAssertState; @@ -107,6 +108,7 @@ public function testOrganisationTeaser(): void { 'title' => 'Organisation name', 'url' => '/en/node/1', 'description' => 'The teaser text', + 'badges' => NULL, 'meta' => 'International organisation | Acronym', 'image' => [ 'src' => 'placeholder_organisation_logo.png', @@ -139,11 +141,18 @@ public function testOrganisationTeaser(): void { $assert->assertPattern($expected_values, $html); $assert->assertVariant('thumbnail_secondary', $html); - // Test short title fallback. - $node->set('oe_content_short_title', 'Organisation short title')->save(); + // Test short title fallback and highlighted label. + $node->set('oe_content_short_title', 'Organisation short title'); + $node->set('sticky', NodeInterface::STICKY)->save(); $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); $expected_values['title'] = 'Organisation short title'; + $expected_values['badges'] = [ + [ + 'label' => 'Highlighted', + 'variant' => 'highlight', + ], + ]; $assert->assertPattern($expected_values, $html); // Create another contact and add it to the node. diff --git a/tests/src/Kernel/PersonRenderTest.php b/tests/src/Kernel/PersonRenderTest.php index b06ae2621..0a8807c0a 100644 --- a/tests/src/Kernel/PersonRenderTest.php +++ b/tests/src/Kernel/PersonRenderTest.php @@ -105,6 +105,7 @@ public function testTeaser(): void { $html = $this->getRenderedNode($node); $expected_values = [ 'title' => 'Mick Jagger', + 'badges' => NULL, 'meta' => NULL, 'image' => [ 'src' => 'user_icon.svg', @@ -243,13 +244,20 @@ public function testTeaser(): void { $second_contact_render = $crawler->filter('article .ecl-content-item__additional_information:nth-child(3) > div:nth-child(2)'); $field_assert->assertPattern($second_contact_expected_values, $second_contact_render->html()); - // Assert Jobs field. + // Assert Jobs field and highlighted label. $job_1 = $this->createPersonJobEntity('job_1', [ 'oe_acting' => TRUE, 'oe_role_reference' => 'http://publications.europa.eu/resource/authority/role-qualifier/ADVIS', ]); $node->set('oe_person_contacts', NULL); - $node->set('oe_person_jobs', $job_1)->save(); + $node->set('oe_person_jobs', $job_1); + $node->set('sticky', NodeInterface::STICKY)->save(); + $expected_values['badges'] = [ + [ + 'label' => 'Highlighted', + 'variant' => 'highlight', + ], + ]; $expected_values['meta'] = '(Acting) Advisor'; $expected_values['additional_information'][1] = new PatternAssertState(new FieldListAssert(), [ 'items' => [ @@ -290,6 +298,10 @@ public function testTeaser(): void { $expected_values = [ 'title' => 'Jagger Mick', + 'badges' => [ + 'label' => 'Highlighted', + 'variant' => 'highlight', + ], 'meta' => 'Singer, Dancer', 'image' => [ 'src' => 'person_portrait.png', diff --git a/tests/src/Kernel/ProjectRenderTest.php b/tests/src/Kernel/ProjectRenderTest.php index 96d1a27d8..fc79931e3 100644 --- a/tests/src/Kernel/ProjectRenderTest.php +++ b/tests/src/Kernel/ProjectRenderTest.php @@ -6,6 +6,7 @@ use Drupal\media\Entity\Media; use Drupal\node\Entity\Node; +use Drupal\node\NodeInterface; use Drupal\oe_content_entity_organisation\Entity\Organisation; use Drupal\Tests\oe_theme\PatternAssertions\FieldListAssert; use Drupal\Tests\oe_theme\PatternAssertions\ListItemAssert; @@ -159,6 +160,7 @@ public function testProjectTeaser(): void { 'title' => 'Project 1', 'url' => '/en/node/1', 'description' => 'The teaser text', + 'badges' => NULL, 'meta' => NULL, 'image' => [ 'src' => 'example_1.jpeg', @@ -179,11 +181,18 @@ public function testProjectTeaser(): void { $assert->assertPattern($expected_values, $html); $assert->assertVariant('thumbnail_secondary', $html); - // Test short title fallback. - $node->set('oe_content_short_title', 'Project short title')->save(); + // Test short title fallback and highlighted label. + $node->set('oe_content_short_title', 'Project short title'); + $node->set('sticky', NodeInterface::STICKY)->save(); $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); $expected_values['title'] = 'Project short title'; + $expected_values['badges'] = [ + [ + 'label' => 'Highlighted', + 'variant' => 'highlight', + ], + ]; $assert->assertPattern($expected_values, $html); } diff --git a/tests/src/Kernel/PublicationRenderTest.php b/tests/src/Kernel/PublicationRenderTest.php index d9872c0f0..cd79a41d7 100644 --- a/tests/src/Kernel/PublicationRenderTest.php +++ b/tests/src/Kernel/PublicationRenderTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\oe_theme\Kernel; use Drupal\node\Entity\Node; +use Drupal\node\NodeInterface; use Drupal\Tests\oe_theme\PatternAssertions\ListItemAssert; use Drupal\Tests\user\Traits\UserCreationTrait; @@ -46,16 +47,24 @@ public function testTeaser(): void { $assert = new ListItemAssert(); $expected_values = [ 'title' => 'Test Publication node', + 'badges' => NULL, 'meta' => "Delegated directive | 15 April 2020\n | Arab Common Market", 'description' => 'Test teaser text.', ]; $assert->assertPattern($expected_values, $html); - // Test short title fallback. - $node->set('oe_content_short_title', 'Publication short title')->save(); + // Test short title fallback and highlighted label. + $node->set('oe_content_short_title', 'Publication short title'); + $node->set('sticky', NodeInterface::STICKY)->save(); $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); $expected_values['title'] = 'Publication short title'; + $expected_values['badges'] = [ + [ + 'label' => 'Highlighted', + 'variant' => 'highlight', + ], + ]; $assert->assertPattern($expected_values, $html); // Add thumbnail. diff --git a/tests/src/Kernel/fixtures/rendering.yml b/tests/src/Kernel/fixtures/rendering.yml index 941f7bc2f..7677035cf 100644 --- a/tests/src/Kernel/fixtures/rendering.yml +++ b/tests/src/Kernel/fixtures/rendering.yml @@ -577,6 +577,9 @@ language_code: "hu" translation_toggle_label: "Other translations" more_info: "Looking for another language which is not on the list? Find out why." + badges: + - label: "Highlighted" + variant: "highlight" assertions: count: 'img.ecl-file__image[src="https://inno-ecl.s3.amazonaws.com/media/examples/example-image.jpg"]': 1 @@ -591,6 +594,7 @@ 'a.ecl-file__translation-download[href="http://example.com/document_fr.xls"]': 1 'a.ecl-file__translation-download[href="http://example.com/document_it.ppt"]': 1 'a.ecl-file__translation-download[href="http://example.com/document_hu.pdf"]': 1 + 'div.ecl-file__label span.ecl-label.ecl-label--highlight': 1 equals: 'div.ecl-file__detail-info div.ecl-file__title': "Example document" 'div.ecl-file__detail-info div.ecl-file__description': 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer quis lorem tellus. Nullam sollicitudin suscipit diam, ac blandit ipsum tempor consectetur. Duis vitae pulvinar turpis. Donec maximus pharetra ex a ultricies.' @@ -616,6 +620,7 @@ '.ecl-file__translation-item:nth-child(3) div.ecl-file__translation-meta': "(166.02 KB - PDF)" '.ecl-file__translation-item:nth-child(3) .ecl-link__label': "Download" 'li.ecl-file__translation-item.ecl-file__translation-description': "Looking for another language which is not on the list? Find out why." + 'div.ecl-file__label span.ecl-label.ecl-label--highlight': "Highlighted" - array: '#type': pattern '#id': file_teaser @@ -667,6 +672,7 @@ 'dt.ecl-description-list__term': 1 'dd.ecl-description-list__definition': 1 'span.ecl-description-list__tag': 2 + 'div.ecl-file__label span.ecl-label.ecl-label--highlight': 0 equals: 'div.ecl-file__detail-info div.ecl-file__title': "Example document" 'div.ecl-file__detail-info div.ecl-file__description': 'Lorem...' @@ -807,14 +813,23 @@ meta: - "Meta 1" - "Meta 2" + badges: + - label: "Highlighted" + variant: "highlight" + - label: "Status: Open" + variant: "high" assertions: count: 'article.ecl-content-item div.ecl-content-item__title a.ecl-link[href="http://example.com"]': 1 'article.ecl-content-item div[role="img"].ecl-u-d-l-block': 0 'article.ecl-content-item div.ecl-content-item__image__before': 0 'article.ecl-content-item div.ecl-content-item__image__after': 0 + 'span.ecl-label.ecl-label--highlight.ecl-u-mr-xs': 1 + 'span.ecl-label.ecl-label--high.ecl-u-mr-xs.ecl-u-type-color-black': 1 equals: - 'article.ecl-content-item div.ecl-content-item__meta': "Meta 1 | Meta 2" + 'article.ecl-content-item div.ecl-content-item__meta span.ecl-label.ecl-label--highlight.ecl-u-mr-xs': "Highlighted" + 'article.ecl-content-item div.ecl-content-item__meta span.ecl-label.ecl-label--high.ecl-u-mr-xs.ecl-u-type-color-black': "Status: Open" + '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: @@ -834,7 +849,7 @@ 'article.ecl-content-item div.ecl-content-item__image__before': 0 'article.ecl-content-item div.ecl-content-item__image__after': 0 equals: - 'article.ecl-content-item div.ecl-content-item__meta': "Meta 1" + 'article.ecl-content-item div.ecl-content-item__meta div.ecl-u-mt-xs': "Meta 1" 'article.ecl-content-item div.ecl-content-item__title .ecl-link': "Item title" 'article.ecl-content-item div.ecl-content-item__description': "Item..." - array: @@ -890,8 +905,8 @@ 'article.ecl-content-item div.ecl-content-item__image__after': 0 equals: 'a.ecl-link.ecl-link--standalone.ecl-link--icon.ecl-link--icon-after svg.ecl-icon.ecl-icon--s.ecl-link__icon' : '' - 'article.ecl-content-item div.ecl-content-item__meta': "Meta 1 | Meta 2" 'article.ecl-content-item div.ecl-content-item__title .ecl-link span.ecl-link__label': "Item title" + '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__description': "
This is the detail. It...
" - array: '#type': pattern @@ -912,7 +927,7 @@ 'article.ecl-content-item div.ecl-content-item__image__before': 0 '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': '
This is the detail with a link...
' - array: @@ -934,7 +949,7 @@ 'article.ecl-content-item div.ecl-content-item__image__before': 0 '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': '<div>This is the detail...' - array: @@ -958,7 +973,7 @@ 'article.ecl-content-item div.ecl-content-item__image__before': 0 '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': '

<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()); + } } /**