From 3ed412fd90c2b30bb4086bcac3b17dfb55a874f9 Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Mon, 22 Jan 2024 13:17:56 +0200 Subject: [PATCH] EWPP-3875: Add a twig function to determine the border color class. --- .../src/TwigExtension/TwigExtension.php | 14 +++++++ .../tests/src/Unit/TwigExtensionTest.php | 40 +++++++++++++++++++ ...--oe-news-sources--oe-news--full.html.twig | 3 +- ...field--oe-contact--oe-link--full.html.twig | 3 +- ...tact--oe-press-contact-url--full.html.twig | 3 +- .../field/field--oe-related-links.html.twig | 3 +- .../oe_contact/oe-contact--full.html.twig | 3 +- 7 files changed, 59 insertions(+), 10 deletions(-) diff --git a/modules/oe_theme_helper/src/TwigExtension/TwigExtension.php b/modules/oe_theme_helper/src/TwigExtension/TwigExtension.php index 11052bfca..ce1ce0c2e 100644 --- a/modules/oe_theme_helper/src/TwigExtension/TwigExtension.php +++ b/modules/oe_theme_helper/src/TwigExtension/TwigExtension.php @@ -97,6 +97,7 @@ public function getFunctions(): array { new TwigFunction('to_ecl_icon', [$this, 'toEclIcon'], ['needs_context' => TRUE]), new TwigFunction('get_link_icon', [$this, 'getLinkIcon'], ['needs_context' => TRUE]), new TwigFunction('ecl_footer_links', [$this, 'eclFooterLinks'], ['needs_context' => TRUE]), + new TwigFunction('ecl_class_border_color', [$this, 'eclBorderColor'], ['needs_context' => TRUE]), ]; } @@ -657,6 +658,19 @@ public function isExternal(string $path): bool { return $this->externalLinks->isExternalLink($path); } + /** + * Determines the proper border color class based on the component library. + * + * @param array $context + * The twig context. + * + * @return string + * The border color class. + */ + public function eclBorderColor(array $context): string { + return $context['ecl_component_library'] === 'ec' ? 'ecl-u-border-color-neutral-40' : 'ecl-u-border-color-primary-10'; + } + /** * Creates a Markup object. * diff --git a/modules/oe_theme_helper/tests/src/Unit/TwigExtensionTest.php b/modules/oe_theme_helper/tests/src/Unit/TwigExtensionTest.php index 76eb89e65..63badca62 100644 --- a/modules/oe_theme_helper/tests/src/Unit/TwigExtensionTest.php +++ b/modules/oe_theme_helper/tests/src/Unit/TwigExtensionTest.php @@ -400,6 +400,46 @@ public function toEclIconProvider(): array { ]; } + /** + * Tests the ECL border color class is properly. + * + * @param string $component_library + * The current component library. + * @param string $expected_class + * The expected border color class. + * + * @covers ::eclBorderColor + * @dataProvider eclBorderColorProvider + */ + public function testEclBorderColor(string $component_library, string $expected_class) { + $context = [ + 'ecl_component_library' => $component_library, + ]; + $result = $this->twig->render("{{ ecl_class_border_color() }}", $context); + $this->assertEquals($expected_class, $result); + } + + /** + * Returns test cases for ::testEclBorderColor(). + * + * @return array[] + * Test cases array. + * + * @see ::testEclBorderColor() + */ + public function eclBorderColorProvider(): array { + return [ + [ + 'ec', + 'ecl-u-border-color-neutral-40', + ], + [ + 'eu', + 'ecl-u-border-color-primary-10', + ], + ]; + } + /** * Test that create_markup filter returns MarkupInterface object. */ diff --git a/templates/field/field--node--oe-news-sources--oe-news--full.html.twig b/templates/field/field--node--oe-news-sources--oe-news--full.html.twig index 12b921ece..b8883ed72 100644 --- a/templates/field/field--node--oe-news-sources--oe-news--full.html.twig +++ b/templates/field/field--node--oe-news-sources--oe-news--full.html.twig @@ -6,11 +6,10 @@ * @see ./core/themes/stable/templates/field/field.html.twig */ #} -{% set _color = ecl_component_library == 'ec' ? 'neutral-40' : 'primary-10' %}

{{ 'Sources'|t }}

{% for item in items %} {% set bubble_cache = item.content|render %} -
+
{% include '@ecl-twig/link' with { link: { type: 'standalone', diff --git a/templates/field/field--oe-contact--oe-link--full.html.twig b/templates/field/field--oe-contact--oe-link--full.html.twig index b5e563b03..ba4565d4d 100644 --- a/templates/field/field--oe-contact--oe-link--full.html.twig +++ b/templates/field/field--oe-contact--oe-link--full.html.twig @@ -6,10 +6,9 @@ * @see ./core/themes/stable/templates/field/field.html.twig */ #} -{% set _color = ecl_component_library == 'ec' ? 'neutral-40' : 'primary-10' %} {% for item in items %} {% set bubble_cache = item.content|render %} -
+
{% include '@ecl-twig/link' with { link: { type: 'standalone', diff --git a/templates/field/field--oe-contact--oe-press-contact-url--full.html.twig b/templates/field/field--oe-contact--oe-press-contact-url--full.html.twig index c3083e1e8..d85858587 100644 --- a/templates/field/field--oe-contact--oe-press-contact-url--full.html.twig +++ b/templates/field/field--oe-contact--oe-press-contact-url--full.html.twig @@ -6,10 +6,9 @@ * @see ./core/themes/stable/templates/field/field.html.twig */ #} -{% set _color = ecl_component_library == 'ec' ? 'neutral-40' : 'primary-10' %} {% for item in items %} {% set bubble_cache = item.content|render %} -
+
{% include '@ecl-twig/link' with { link: { type: 'standalone', diff --git a/templates/field/field--oe-related-links.html.twig b/templates/field/field--oe-related-links.html.twig index 0e467ed6a..e567ccae7 100644 --- a/templates/field/field--oe-related-links.html.twig +++ b/templates/field/field--oe-related-links.html.twig @@ -1,8 +1,7 @@ -{% set _color = ecl_component_library == 'ec' ? 'neutral-40' : 'primary-10' %}

{{ 'Related links'|t }}

{% for item in items %} {% set bubble_cache = item.content|render %} -
+
{% include '@ecl-twig/link' with { link: { type: 'standalone', diff --git a/templates/oe_contact/oe-contact--full.html.twig b/templates/oe_contact/oe-contact--full.html.twig index d9a3c5c90..9c79d90c0 100644 --- a/templates/oe_contact/oe-contact--full.html.twig +++ b/templates/oe_contact/oe-contact--full.html.twig @@ -6,7 +6,6 @@ * @see ./modules/contrib/oe_content_entity/modules/oe_content_entity_contact/templates/oe-contact.html.twig */ #} -{% set _color = ecl_component_library == 'ec' ? 'neutral-40' : 'primary-10' %} {% set image = content.oe_image|field_value|render %}
{% block title %} @@ -27,7 +26,7 @@ {% endif %} {{ content.group_contact_information }} {% if not entity.oe_press_contact_url.isEmpty() or not entity.oe_link.isEmpty() %} -
+
{{ content.oe_press_contact_url }} {{ content.oe_link }}