Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EWPP-1360] EWPP-1363: Style Sources field in full view mode. #903

Merged
merged 2 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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-EPIC-EWPP-1360-News-v3",
"openeuropa/oe_corporate_blocks": "~4.0",
"openeuropa/oe_corporate_countries": "~2.0",
"openeuropa/oe_media": "~1.12",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -92,7 +105,7 @@ content:
third_party_settings: { }
oe_related_links:
type: link
weight: 3
weight: 5
region: content
label: hidden
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -92,7 +105,7 @@ content:
third_party_settings: { }
oe_related_links:
type: link
weight: 3
weight: 5
region: content
label: hidden
settings:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{#
/**
* @file
* News sources field template.
*
* @see ./core/themes/stable/templates/field/field.html.twig
*/
#}
<h2 class="ecl-u-type-heading-2">{{ 'Sources'|t }}</h2>
<div class="ecl-list">
{% for item in items %}
<article class="ecl-content-item ecl-u-d-s-flex ecl-u-pb-m">
<div class="ecl-u-flex-grow-1">
<div class="ecl-content-item__title ecl-u-type-heading-5 ecl-u-mb-xs ecl-u-mt-none">
{%- 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 -%}
</div>
</div>
</article>
{% endfor %}
</div>
Comment on lines +9 to +36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it would be more suitable to reuse the list_item pattern like we did for related_links field.
See \oe_theme_preprocess_field function inside oe_theme.theme.

Copy link
Member

@sergepavle sergepavle Aug 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, we can't, for now, use the list_item pattern according to fact that we can't control the link's icon. I think it would be the more preferable solution anyway to use a pattern but with additional parameter for controlling the link's type (for adding external icon if needed).
I suppose it can be impelmented in follow-up ticket.

42 changes: 39 additions & 3 deletions tests/Functional/ContentNewsRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
nagyad marked this conversation as resolved.
Show resolved Hide resolved
$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();
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down