From 80ed112ff164fc4d082b3a1bb6c58ac7dcd0592c Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Mon, 2 Aug 2021 20:26:25 +0300 Subject: [PATCH 1/2] EWPP-1363: Style Sources field in full view mode. --- composer.json | 2 +- docker-compose.yml | 2 +- ....entity_view_display.node.oe_news.full.yml | 19 ++++++++-- ....entity_view_display.node.oe_news.full.yml | 19 ++++++++-- ...--oe-news-sources--oe-news--full.html.twig | 36 +++++++++++++++++++ 5 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 templates/field/field--node--oe-news-sources--oe-news--full.html.twig diff --git a/composer.json b/composer.json index 05079fb5b..7e2304bfe 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "openeuropa/behat-transformation-context": "~0.1", "openeuropa/code-review": "~1.5", "openeuropa/drupal-core-require-dev": "^8.9.14", - "openeuropa/oe_content": "dev-EWPP-1362", + "openeuropa/oe_content": "dev-EWPP-1363", "openeuropa/oe_corporate_blocks": "~4.0", "openeuropa/oe_corporate_countries": "~2.0", "openeuropa/oe_media": "~1.12", diff --git a/docker-compose.yml b/docker-compose.yml index 5f9933e42..e93efe5b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: XDEBUG_MODE: "develop, debug" PHP_IDE_CONFIG: "serverName=Docker" # Enable step debugging for all PHP request. See ./README.md#step-debugging for more information. - XDEBUG_SESSION: 1 + # XDEBUG_SESSION: 1 mysql: image: percona/percona-server:5.7 command: --innodb-log-file-size=1G --max_allowed_packet=1G --innodb-buffer-pool-size=512M --wait_timeout=3000 --net_write_timeout=3000 --log_error_verbosity=3 diff --git a/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.full.yml b/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.full.yml index 34eddde0d..541723cea 100644 --- a/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.full.yml +++ b/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.full.yml @@ -9,6 +9,7 @@ dependencies: - field.field.node.oe_news.oe_news_featured_media - field.field.node.oe_news.oe_news_last_updated - field.field.node.oe_news.oe_news_location + - field.field.node.oe_news.oe_news_sources - field.field.node.oe_news.oe_news_types - field.field.node.oe_news.oe_publication_date - field.field.node.oe_news.oe_reference_code @@ -34,7 +35,7 @@ third_party_settings: - oe_author - oe_news_location parent_name: '' - weight: 1 + weight: 3 format_type: oe_theme_helper_field_list_pattern region: content format_settings: @@ -67,7 +68,7 @@ content: third_party_settings: { } oe_news_contacts: type: entity_reference_revisions_entity_view - weight: 2 + weight: 4 region: content label: above settings: @@ -82,6 +83,18 @@ content: settings: link: false third_party_settings: { } + oe_news_sources: + type: link + weight: 1 + region: content + label: hidden + settings: + trim_length: null + url_only: false + url_plain: false + rel: '0' + target: '0' + third_party_settings: { } oe_reference_code: type: string weight: 12 @@ -92,7 +105,7 @@ content: third_party_settings: { } oe_related_links: type: link - weight: 3 + weight: 5 region: content label: hidden settings: diff --git a/modules/oe_theme_content_news/config/post_updates/00009_update_full_view_display/core.entity_view_display.node.oe_news.full.yml b/modules/oe_theme_content_news/config/post_updates/00009_update_full_view_display/core.entity_view_display.node.oe_news.full.yml index 34eddde0d..541723cea 100644 --- a/modules/oe_theme_content_news/config/post_updates/00009_update_full_view_display/core.entity_view_display.node.oe_news.full.yml +++ b/modules/oe_theme_content_news/config/post_updates/00009_update_full_view_display/core.entity_view_display.node.oe_news.full.yml @@ -9,6 +9,7 @@ dependencies: - field.field.node.oe_news.oe_news_featured_media - field.field.node.oe_news.oe_news_last_updated - field.field.node.oe_news.oe_news_location + - field.field.node.oe_news.oe_news_sources - field.field.node.oe_news.oe_news_types - field.field.node.oe_news.oe_publication_date - field.field.node.oe_news.oe_reference_code @@ -34,7 +35,7 @@ third_party_settings: - oe_author - oe_news_location parent_name: '' - weight: 1 + weight: 3 format_type: oe_theme_helper_field_list_pattern region: content format_settings: @@ -67,7 +68,7 @@ content: third_party_settings: { } oe_news_contacts: type: entity_reference_revisions_entity_view - weight: 2 + weight: 4 region: content label: above settings: @@ -82,6 +83,18 @@ content: settings: link: false third_party_settings: { } + oe_news_sources: + type: link + weight: 1 + region: content + label: hidden + settings: + trim_length: null + url_only: false + url_plain: false + rel: '0' + target: '0' + third_party_settings: { } oe_reference_code: type: string weight: 12 @@ -92,7 +105,7 @@ content: third_party_settings: { } oe_related_links: type: link - weight: 3 + weight: 5 region: content label: hidden settings: 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 new file mode 100644 index 000000000..113220a65 --- /dev/null +++ b/templates/field/field--node--oe-news-sources--oe-news--full.html.twig @@ -0,0 +1,36 @@ +{# +/** + * @file + * News sources field template. + * + * @see ./core/themes/stable/templates/field/field.html.twig + */ +#} +

{{ 'Sources'|t }}

+
+ {% for item in items %} +
+
+
+ {%- if item.content['#url'] %} + {% include '@ecl-twig/link' with { + link: { + type: 'standalone', + icon_position: 'after', + label: item.content['#title'], + path: item.content['#url'] + }, + icon: { + name: 'external', + size: 's', + path: ecl_icon_path + } + } %} + {% else %} + {{ item.content['#title'] }} + {%- endif -%} +
+
+
+ {% endfor %} +
From 191b1b2c9e1d345a09cf8746b74a622660767724 Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Tue, 3 Aug 2021 11:49:29 +0300 Subject: [PATCH 2/2] EWPP-1363: Update test coverage. --- composer.json | 2 +- tests/Functional/ContentNewsRenderTest.php | 42 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 7e2304bfe..53906ac1c 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "openeuropa/behat-transformation-context": "~0.1", "openeuropa/code-review": "~1.5", "openeuropa/drupal-core-require-dev": "^8.9.14", - "openeuropa/oe_content": "dev-EWPP-1363", + "openeuropa/oe_content": "dev-EPIC-EWPP-1360-News-v3", "openeuropa/oe_corporate_blocks": "~4.0", "openeuropa/oe_corporate_countries": "~2.0", "openeuropa/oe_media": "~1.12", diff --git a/tests/Functional/ContentNewsRenderTest.php b/tests/Functional/ContentNewsRenderTest.php index 6c91a5646..0fedcda51 100644 --- a/tests/Functional/ContentNewsRenderTest.php +++ b/tests/Functional/ContentNewsRenderTest.php @@ -85,6 +85,42 @@ public function testNewsRendering(): void { $this->assertEquals('http://www.example.org', $header_link->getAttribute('href')); $this->assertEquals('http://www.example.org', $header_link->getText()); + // Assert Sources field content. + $node->set('oe_news_sources', [ + [ + 'uri' => 'internal:/node', + 'title' => 'Internal source link', + ], [ + 'uri' => 'https://example.com', + 'title' => 'External source link', + ], + ])->save(); + $this->drupalGet($node->toUrl()); + + // Assert header. + $source_links_header = $this->assertSession()->elementExists('css', 'article[role=article] > div > h2:nth-child(2)'); + $this->assertContentHeader($source_links_header, 'Sources'); + $source_links = $this->getSession()->getPage()->findAll('css', 'div.ecl-list:nth-child(3) article.ecl-content-item'); + $this->assertCount(2, $source_links); + $selector = 'div.ecl-content-item__title.ecl-u-type-heading-5.ecl-u-mb-xs.ecl-u-mt-none a.ecl-link.ecl-link--standalone.ecl-link--icon.ecl-link--icon-after'; + $svg_locator = 'svg.ecl-icon.ecl-icon--s.ecl-link__icon'; + // Assert the internal source link content. + $first_source_link = $source_links[0]->find('css', $selector); + $this->assertEquals('/build/node', $first_source_link->getAttribute('href')); + $first_source_text = $source_links[0]->find('css', $selector . ' span.ecl-link__label'); + $this->assertEquals('Internal source link', $first_source_text->getText()); + $first_source_link_svg = $source_links[0]->findAll('css', $svg_locator); + $icon = $first_source_link_svg[0]->findAll('css', 'use'); + $this->assertContains('external', $icon[0]->getAttribute('xlink:href')); + // Assert the external source link content. + $second_source_link = $source_links[1]->find('css', $selector); + $this->assertEquals('https://example.com', $second_source_link->getAttribute('href')); + $second_source_text = $source_links[1]->find('css', $selector . ' span.ecl-link__label'); + $this->assertEquals('External source link', $second_source_text->getText()); + $second_source_link_svg = $source_links[1]->findAll('css', $svg_locator); + $icon = $second_source_link_svg[0]->findAll('css', 'use'); + $this->assertContains('external', $icon[0]->getAttribute('xlink:href')); + $node->set('oe_news_location', 'http://publications.europa.eu/resource/authority/place/ARE_AUH'); $node->set('oe_news_types', 'http://publications.europa.eu/resource/authority/resource-type/PUB_GEN'); $node->save(); @@ -201,9 +237,9 @@ public function testNewsRendering(): void { ])->save(); $this->drupalGet($node->toUrl()); - $related_links_header = $this->assertSession()->elementExists('css', 'article[role=article] > div > h2'); + $related_links_header = $this->assertSession()->elementExists('css', 'article[role=article] > div > h2:nth-child(7)'); $this->assertContentHeader($related_links_header, 'Related links'); - $related_links_content = $this->assertSession()->elementExists('css', 'article[role=article] > div > div.ecl-list article.ecl-content-item:nth-child(1)'); + $related_links_content = $this->assertSession()->elementExists('css', 'div.ecl-list:nth-child(8) article.ecl-content-item:nth-child(1)'); $link_assert = new ListItemAssert(); $link_expected_values = [ 'url' => '/build/node', @@ -212,7 +248,7 @@ public function testNewsRendering(): void { $link_assert->assertPattern($link_expected_values, $related_links_content->getOuterHtml()); $link_assert->assertVariant('default', $related_links_content->getOuterHtml()); - $related_links_content = $this->assertSession()->elementExists('css', 'article[role=article] > div > div.ecl-list article.ecl-content-item:nth-child(2)'); + $related_links_content = $this->assertSession()->elementExists('css', 'div.ecl-list:nth-child(8) article.ecl-content-item:nth-child(2)'); $link_expected_values = [ 'url' => 'https://example.com', 'title' => 'External link',