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-4825: Preview extension for file patterns. #1517

Merged
merged 1 commit into from
Oct 28, 2024
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
18 changes: 17 additions & 1 deletion templates/patterns/file_teaser/file_teaser.ui_patterns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ file_teaser:
size: "140000"
name: "document.pdf"
language_code: "en"
link_attributes:
type: "array"
label: "The download link attributes"
description: "Any additional attributes to be added to the file download link."
preview:
- "name": "data-attribute-foo"
"value": "bar"
thumbnail:
type: "array"
label: "Thumbnail"
Expand All @@ -43,7 +50,7 @@ file_teaser:
translations:
type: "array"
label: "Files"
description: "List of teaser (teaser is deprecated - to be removed in 5.x) text/FileValueObject pairs, respectively keyed with 'teaser' and 'file'."
description: "List of items with the following properties: teaser (teaser is deprecated - to be removed in 5.x) text, FileValueObject and link attributes, respectively keyed with 'teaser', 'file' and 'link_attributes'."
preview:
- teaser: "Morbi fringilla turpis augue, et interdum ipsum egestas sed. Proin tristique, ante id aliquet malesuada, lorem dolor vulputate magna, a commodo purus ante nec massa."
file:
Expand All @@ -53,6 +60,9 @@ file_teaser:
size: "150000"
name: "document.pdf"
language_code: "fr"
link_attributes:
- "name": "data-attribute-translation-foo"
"value": "bar"
- teaser: "Proin sagittis nisi hendrerit purus porta, at suscipit est hendrerit. Duis facilisis augue imperdiet, pharetra nisl sed, molestie nulla."
file:
title: "Italian translation"
Expand All @@ -61,6 +71,9 @@ file_teaser:
size: "160000"
name: "document.doc"
language_code: "it"
link_attributes:
- "name": "data-attribute-translation-foo"
"value": "bar"
- teaser: "Duis eget lacinia arcu. Nullam mattis ornare nibh. Proin tristique, ante id aliquet malesuada. Pellentesque porttitor commodo libero sed fringilla. Curabitur varius sodales elit, id tincidunt erat. Aenean tincidunt luctus molestie."
file:
title: "Hungarian translation"
Expand All @@ -69,6 +82,9 @@ file_teaser:
size: "170000"
name: "document.pdf"
language_code: "hu"
link_attributes:
- "name": "data-attribute-translation-foo"
"value": "bar"
translation_toggle_label:
type: "text"
label: "Translation toggle label"
Expand Down
2 changes: 2 additions & 0 deletions templates/patterns/file_teaser/pattern-file-teaser.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'icon': {
'path': ecl_icon_path,
},
'extra_attributes': item.link_attributes|default([]),
},
'lang_full': item.file.language_code|to_native_language
}]) %}
Expand Down Expand Up @@ -116,6 +117,7 @@
'icon': {
'path': ecl_icon_path,
},
'extra_attributes': link_attributes|default([]),
},
'translation': {
'toggle': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ file_translation:
size: "150000"
name: "document.pdf"
language_code: "en"
link_attributes:
Copy link
Member

@sergepavle sergepavle Oct 25, 2024

Choose a reason for hiding this comment

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

Why in the file_teaser pattern we add the possibility to add additional attributes but in the file_translation pattern we don't have a chance to specify extra_attributes for each translation?
I've checked in ewcms but didn't find that it works.
Is it intentional?
image

Copy link
Member

Choose a reason for hiding this comment

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

I've checked and seems like it is possible to add extra_attributes for file_translation items as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is limited by the fact, that file_translation has a different definition of the translations property. It does not allow to pass any additional data along with the translated file (it just takes a list of FileValueObject). So I can't pass the extra_attributes too. To change it, i would have to refactor the pattern and all references to it.

type: "array"
label: "The download link attributes"
description: "Any additional attributes to be added to the file download link."
preview:
- "name": "data-attribute-foo"
"value": "bar"
translations:
type: "array"
label: "Files"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
'icon': {
'path': ecl_icon_path,
},
'extra_attributes': link_attributes|default([]),
},
'translation': {
'toggle': {
Expand Down
25 changes: 25 additions & 0 deletions tests/src/Kernel/fixtures/rendering.yml
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,9 @@
mime: "application/pdf"
size: "10000"
language_code: "en"
link_attributes:
- name: "data-attribute-foo"
value: "bar"
translations:
- mime: "application/vnd.ms-excel"
url: "http://example.com/document_fr.xls"
Expand Down Expand Up @@ -833,6 +836,7 @@
count:
'svg.ecl-file__icon': 1
'a.ecl-file__download[href="http://example.com"]': 1
'a.ecl-file__download[data-attribute-foo="bar"]': 1
'div.ecl-file__translation-container': 1
'li.ecl-file__translation-item a.ecl-file__translation-download': 4
'a.ecl-file__translation-download[href="http://example.com/document_fr.xls"]': 1
Expand Down Expand Up @@ -884,6 +888,7 @@
count:
'svg.ecl-file__icon': 1
'a.ecl-file__download[href="http://example.com"]': 1
'a.ecl-file__download[data-attribute-foo="bar"]': 0
'div.ecl-file__translation-container': 1
'li.ecl-file__translation-item a.ecl-file__translation-download': 1
'a.ecl-file__translation-download[href="http://example.com/document_fr.xls"]': 1
Expand All @@ -910,6 +915,9 @@
mime: "application/pdf"
size: "140000"
language_code: "en"
link_attributes:
- name: "data-attribute-foo"
value: "bar"
thumbnail:
src: "https://inno-ecl.s3.amazonaws.com/media/examples/example-image.jpg"
alt: "thumbnail alt"
Expand All @@ -924,6 +932,9 @@
size: "150000"
name: "document.xls"
language_code: "fr"
link_attributes:
- name: "data-attribute-translation-foo"
value: "bar"
- teaser: "Proin sagittis nisi hendrerit purus porta, at suscipit est hendrerit. Duis facilisis augue imperdiet, pharetra nisl sed, molestie nulla."
file:
title: "Italian translation"
Expand All @@ -932,6 +943,9 @@
size: "160000"
name: "document.ppt"
language_code: "it"
link_attributes:
- name: "data-attribute-translation-foo"
value: "bar"
- teaser: "Duis eget lacinia arcu. Nullam mattis ornare nibh. Proin tristique, ante id aliquet malesuada. Pellentesque porttitor commodo libero sed fringilla. Curabitur varius sodales elit, id tincidunt erat. Aenean tincidunt luctus molestie."
file:
title: "Hungarian translation"
Expand All @@ -940,6 +954,9 @@
size: "170000"
name: "document.pdf"
language_code: "hu"
link_attributes:
- name: "data-attribute-translation-foo"
value: "bar"
- teaser: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce at finibus purus, eu ultricies nisl. Vivamus vitae ex lectus. In hac habitasse platea dictumst. Proin malesuada est eget vulputate malesuada."
file:
title: "Portugies translation"
Expand All @@ -948,6 +965,9 @@
size: "180000"
name: "document.doc"
language_code: "pt-pt"
link_attributes:
- name: "data-attribute-translation-foo"
value: "bar"
translation_toggle_label: "Other translations"
more_info: "Looking for another language which is not on the list? Find out why."
badges:
Expand All @@ -962,6 +982,8 @@
'img.ecl-file__image[alt="thumbnail alt"]': 1
'a.ecl-file__download[href="http://example.com"]': 1
'div.ecl-file.ecl-file--thumbnail[extra-attr="extra value"]': 1
'a.ecl-file__download[data-attribute-foo="bar"]': 1
'div.ecl-file.ecl-file--thumbnail': 1
'div.ecl-file__container div.ecl-file__info ul.ecl-file__detail-meta': 1
'div.ecl-file__container div.ecl-file__info': 1
'div.ecl-file__translation-container': 1
Expand All @@ -971,6 +993,7 @@
'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
'a.ecl-file__translation-download[href="http://example.com/document_pt.doc"]': 1
'a.ecl-file__translation-download[data-attribute-translation-foo="bar"]': 4
'div.ecl-file__label span.ecl-label.ecl-label--highlight': 1
equals:
'div.ecl-file__info div.ecl-file__title': "Example document"
Expand Down Expand Up @@ -1055,13 +1078,15 @@
'img.ecl-file__image[src="https://inno-ecl.s3.amazonaws.com/media/examples/example-image.jpg"]': 1
'img.ecl-file__image[alt="thumbnail alt"]': 1
'a.ecl-file__download[href="http://example.com"]': 1
'a.ecl-file__download[data-attribute-foo="bar"]': 0
'div.ecl-file.ecl-file--thumbnail': 1
'div.ecl-file__container div.ecl-file__info ul.ecl-file__detail-meta': 1
'div.ecl-file__container div.ecl-file__info': 1
'div.ecl-file__translation-container': 1
'ul.ecl-file__translation-list': 1
'li.ecl-file__translation-item a.ecl-file__translation-download': 1
'a.ecl-file__translation-download[href="http://example.com/document_fr.xls"]': 1
'a.ecl-file__translation-download[data-attribute-translation-foo="bar"]': 0
'div.ecl-file__taxonomy': 1
'dl.ecl-description-list': 1
'dt.ecl-description-list__term': 3
Expand Down
24 changes: 24 additions & 0 deletions tests/src/PatternAssertions/FileTeaserAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ protected function getAssertions($variant): array {
$assertions['lists'] = [
[$this, 'assertLists'],
];
$assertions['link_attributes'] = [
[$this, 'assertLinkAttributes'],
];
$assertions['badge'] = [
[$this, 'assertBadge'],
'div.ecl-file--thumbnail div.ecl-file__container div.ecl-file__info div.ecl-file__label',
Expand Down Expand Up @@ -100,6 +103,20 @@ protected function assertFile(array $expected_file, Crawler $crawler): void {
$this->assertElementAttribute($expected_file['url'], 'a.ecl-file__download', 'href', $file_footer);
}

/**
* Asserts the attributes of the download link.
*
* @param array $expected_link_attributes
* The expected link attributes.
* @param \Symfony\Component\DomCrawler\Crawler $crawler
* The DomCrawler where to check the element.
*/
protected function assertLinkAttributes(array $expected_link_attributes, Crawler $crawler): void {
foreach ($expected_link_attributes as $attribute => $value) {
$this->assertElementAttribute($value, 'a.ecl-file__download', $attribute, $crawler);
}
}

/**
* {@inheritdoc}
*/
Expand All @@ -116,6 +133,13 @@ protected function assertTranslation(array $expected_file, Crawler $crawler): vo

// Assert download link.
$this->assertElementAttribute($expected_file['url'], 'a.ecl-file__translation-download', 'href', $crawler);

// Assert download link attributes.
if (isset($expected_file['link_attributes'])) {
foreach ($expected_file['link_attributes'] as $attribute => $value) {
$this->assertElementAttribute($value, 'a.ecl-file__translation-download', $attribute, $crawler);
}
}
}

/**
Expand Down