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

OEL-3343: Copyright overlay. #430

Open
wants to merge 26 commits into
base: EPIC/OEL-3442
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ca889ba
OEL-3343: Copyright overlay.
tibi2303 Sep 11, 2024
953dee4
OEL-3343: Removed unused param.
tibi2303 Sep 11, 2024
e42fa6c
OEL-3343: Improvements on copyright.
tibi2303 Sep 13, 2024
fd86819
OEL-3343: Added also title param.
tibi2303 Sep 13, 2024
6cb6883
OEL-3343: Overlay tests fixes and changed to rem approach.
tibi2303 Sep 16, 2024
8d84145
OEL-3343: Changed to standalone pattern and added js tests.
tibi2303 Sep 23, 2024
c1f9e94
OEL-3343: Fixed tests.
tibi2303 Sep 23, 2024
9f3b5e3
OEL-3343: Added selenium to drone.
tibi2303 Sep 23, 2024
e94a2b7
OEL-3343: Updated markup tests.
tibi2303 Sep 23, 2024
30e0bd9
OEL-3343: Grump code.
tibi2303 Sep 23, 2024
5a19126
OEL-3343: Bug fixing copy and improvement on comments.
tibi2303 Sep 25, 2024
96480b2
OEL-3343: Updated tests.
tibi2303 Sep 25, 2024
848ade3
OEL-3343: Improve readability with heredoc.
drishu Sep 25, 2024
9254952
OEL-3343: Remove detach trigger filter.
drishu Sep 25, 2024
fddda35
OEL-3343: Use once js in detach for consistency.
drishu Sep 25, 2024
531fe2e
OEL-3343: Remove redundant port expose.
drishu Sep 25, 2024
dc58ec7
OEL-3343: Remove redundant template variables.
drishu Sep 25, 2024
2b124ba
OEL-3343: Harmonize attribute creation.
drishu Sep 25, 2024
ebe82c3
OEL-3343: Prefix preview.
drishu Sep 25, 2024
ac82f43
OEL-3343: Test both copyright elements.
drishu Sep 26, 2024
c6cf835
OEL-3343: Improve example texts.
drishu Sep 26, 2024
6ddfe8e
OEL-3343: Remove redundant space.
drishu Sep 26, 2024
225cffe
OEL-3343: Add test for attribute override.
drishu Sep 26, 2024
f81998d
OEL-3343: Diversify testing texts.
drishu Sep 26, 2024
815722c
OEL-3343: Changed to copyright-content as unique ID.
tibi2303 Sep 27, 2024
6495de2
OEL-3343: Updated markup tests.
tibi2303 Sep 27, 2024
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
6 changes: 6 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ services:
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=drupal
selenium:
image: git.fpfis.tech.ec.europa.eu/fpfis/dependency_proxy/containers/selenium/standalone-chrome:4.1.3-20220405
environment:
- DISPLAY=:99
- NODE_MAX_INSTANCES=5
- NODE_MAX_SESSION=5

pipeline:
npm-build:
Expand Down
9 changes: 9 additions & 0 deletions bcl-builder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ const includePaths = [nodeModules];

module.exports = {
styles: [
{
entry: path.resolve(outputFolder, "resources/sass/copyright_overlay.scss"),
dest: path.resolve(outputFolder, "assets/css/copyright-overlay.style.min.css"),
options: {
includePaths,
minify: true,
sourceMap: "file",
},
},
{
entry: path.resolve(outputFolder, "resources/sass/oe_bootstrap_theme.style.scss"),
dest: path.resolve(outputFolder, "assets/css/oe_bootstrap_theme.style.min.css"),
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ services:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
# ports:
# - 3306:3306
selenium:
image: selenium/standalone-chrome:4.1.3
environment:
- DISPLAY=:99
- VNC_NO_PASSWORD=1
ports:
- '5900:5900'
expose:
- '4444'
shm_size: 2g
node:
image: node:18.12.0
user: "node"
Expand Down
8 changes: 8 additions & 0 deletions includes/pattern.inc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ function oe_bootstrap_theme_preprocess_pattern_accordion(array &$variables): voi
$variables['accordion_id'] = Html::getUniqueId('bcl-accordion');
}

/**
* Implements hook_preprocess_HOOK().
*/
function oe_bootstrap_theme_preprocess_pattern_copyright_overlay(array &$variables): void {
$variables['modal_id'] = Html::getUniqueId('bcl-copyright-modal');
$variables['copy_selector'] = Html::getUniqueId('copy-selector');
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use copyright-content as ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed.

}

/**
* Implements hook_preprocess_HOOK().
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Drupal\Core\Render\RenderContext;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Url;
use Drupal\oe_bootstrap_theme\ValueObject\ImageValueObject;
use Drupal\Tests\oe_bootstrap_theme\Kernel\AbstractKernelTestBase;
use Drupal\oe_bootstrap_theme\ValueObject\ImageValueObject;
use PHPUnit\Framework\ExpectationFailedException;
use Symfony\Component\DomCrawler\Crawler;
use Twig\Markup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Drupal\Tests\oe_bootstrap_theme_helper\Unit;

use Drupal\oe_bootstrap_theme_helper\Plugin\Filter\BootstrapTable;
use Drupal\Tests\UnitTestCase;
use Drupal\oe_bootstrap_theme_helper\Plugin\Filter\BootstrapTable;

/**
* Tests the bootstrap table filter.
Expand Down
14 changes: 14 additions & 0 deletions oe_bootstrap_theme.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,17 @@ drupal.progress:
inpage_navigation:
js:
resources/js/inpage_navigation.js: {}

copy_clipboard:
js:
resources/js/copy_clipboard.js: {}
brummbar marked this conversation as resolved.
Show resolved Hide resolved
dependencies:
- core/drupal
- core/once

pattern.copyright_overlay:
drishu marked this conversation as resolved.
Show resolved Hide resolved
css:
theme:
assets/css/copyright-overlay.style.min.css: {}
dependencies:
- oe_bootstrap_theme/copy_clipboard
2 changes: 2 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<env name="SIMPLETEST_IGNORE_DIRECTORIES" value="vendor,node_modules,${drupal.root}"/>
<env name="SIMPLETEST_BASE_URL" value="${drupal.base_url}"/>
<env name="SIMPLETEST_DB" value="mysql://${drupal.database.user}:${drupal.database.password}@${drupal.database.host}:${drupal.database.port}/${drupal.database.name}"/>
<!-- @todo When dropping support for 10.2.x, rename "chromeOptions" to "goog:chromeOptions". -->
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value='["${selenium.browser}", {"browserName":"chrome","chromeOptions":{"w3c": false, "args":["--no-sandbox", "--start-maximized", "--disable-gpu", "--window-size=1280,800", "--disable-dev-shm-usage", "--DNS-prefetch-disable", "--disable-translate", "--ignore-certificate-errors", "--test-type", "--disable-extensions", "--incognito", "--disable-infobars"]}}, "${selenium.host}:${selenium.port}/wd/hub"]'/>
</php>
<testsuites>
<testsuite name="OpenEuropa Bootstrap Theme">
Expand Down
32 changes: 32 additions & 0 deletions resources/js/copy_clipboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @file
* Attaches behaviors to copy text to clipboard for elements with data-copy-target attribute.
*/
(function (Drupal) {

const handleClick = function (event) {
const element = event.currentTarget;
const targetSelector = element.getAttribute('data-copy-target');
const targetElement = document.querySelector(targetSelector);
Copy link
Contributor

Choose a reason for hiding this comment

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

So we decided to go for the approach where is the user that needs to ensure to pass a selector that triggers one element only?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, i think it's better because we let the user make extended selectors and it's up to them to provide the correct one.


if (targetElement) {
const copyText = targetElement.innerText || targetElement.value;
navigator.clipboard.writeText(copyText);
}
};

Drupal.behaviors.copyClipboard = {
attach: function (context) {
once('oebt-clipcopy', '[data-copy-target]', context).forEach(function (element) {
element.addEventListener('click', handleClick);
});
},

detach: function (context, settings, trigger) {
once.remove('oebt-clipcopy', '[data-copy-target]', context).forEach(function (element) {
element.removeEventListener('click', handleClick);
});
}
};

})(Drupal);
20 changes: 20 additions & 0 deletions resources/sass/copyright_overlay.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.copyright-overlay {
background-color: rgba(var(--bs-white-rgb),var(--bs-bg-opacity));
color: var(--bs-gray-700);
padding: 0 0.5rem;
display: inline-flex;
.copyright-preview {
display: inline-block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 7rem;
font-size: 0.875rem;
}
.copyright-trigger {
font-size: 0.875rem;
}
.copyright-header {
font-size: 1.25rem;
}
}
5 changes: 5 additions & 0 deletions runner.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ drupal:
- "vendor"
- "${drupal.root}"

selenium:
host: "http://selenium"
port: "4444"
browser: "chrome"

commands:
drupal:site-setup:
- { task: "run", command: "drupal:symlink-project" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
copyright_overlay:
label: 'Copyright overlay'
description: 'A component to show copyright information.'
fields:
trigger_label:
type: text
label: 'Trigger label'
description: 'The label of the modal trigger. Optional.'
preview: 'View more'
modal_title:
type: text
label: 'Modal title'
description: 'The title of the modal header. Optional.'
preview: 'Copyright'
content:
type: render
label: 'Content'
description: 'Copyright overlay content.'
preview: '© Copyright ipsum amet <a href="#">John Doe</a> on <a href="#">Doe Images</a>.'
settings:
drishu marked this conversation as resolved.
Show resolved Hide resolved
trigger_attributes:
type: attributes
label: Trigger attributes
description: Extra attributes for the modal trigger
drishu marked this conversation as resolved.
Show resolved Hide resolved
allow_token: true
attributes:
type: attributes
label: Copyright overlay attributes
description: Extra attributes for the copyright overlay
allow_token: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{#
/**
* @file
* Template override for preview mode of "Copyright overlay" pattern.
*/
#}

{{ pattern('copyright_overlay', {
content: content,
}) }}

{{ pattern('copyright_overlay', {
content: '© Second copyright element. Suspendisse vel mauris vitae ipsum blandit condimentum ut eget quam.',
}) }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{#
/**
* @file
* Copyright overlay pattern.
*/
#}
{{ attach_library('oe_bootstrap_theme/pattern.copyright_overlay') }}

{% set _footer %}
{% include '@oe-bcl/button' with {
label: 'Copy Copyright'|t,
attributes: create_attribute({
'data-bs-dismiss': 'modal',
'data-copy-target': '#' ~ copy_selector
})
} only %}
{% endset %}

{% set _content %}
<div{{ create_attribute({
'class': 'copyright-content',
'id': copy_selector
}) }}>
{{ content }}
</div>
{% endset %}

<div{{ attributes.addClass('copyright-overlay') }}>
<span class="copyright-preview">
{{ content }}
</span>

{{ pattern('link', {
label: trigger_label|default('View more'|t),
path: '#',
attributes: trigger_attributes
.addClass('copyright-trigger')
.setAttribute('data-bs-toggle', 'modal')
.setAttribute('data-bs-target', '#' ~ modal_id),
}) }}

{{ pattern('modal', {
'title': modal_title|default('Copyright'|t),
'show_close_button': true,
'body': _content,
'footer': _footer,
'attributes': create_attribute({
id: modal_id
})
}) }}
</div>
2 changes: 1 addition & 1 deletion tests/src/Functional/CheckboxSwitchWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Drupal\Tests\oe_bootstrap_theme\Functional;

use Drupal\Tests\BrowserTestBase;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\BrowserTestBase;

/**
* Tests the checkbox switch third party settings on compatible widgets.
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Functional/ThemeSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Drupal\Tests\oe_bootstrap_theme\Functional;

use Drupal\oe_bootstrap_theme\BackwardCompatibility;
use Drupal\Tests\BrowserTestBase;
use Drupal\oe_bootstrap_theme\BackwardCompatibility;

/**
* Tests the theme settings.
Expand Down
77 changes: 77 additions & 0 deletions tests/src/FunctionalJavascript/CopyClipboardTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

namespace Drupal\Tests\oe_bootstrap_theme\FunctionalJavascript;

use Behat\Mink\Element\NodeElement;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;

/**
* Tests the copy to clipboard javascript behaviour.
*/
class CopyClipboardTest extends WebDriverTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'oe_bootstrap_theme';

/**
* {@inheritdoc}
*/
protected static $modules = [
'oe_bootstrap_theme_helper',
'system',
'ui_patterns',
'ui_patterns_settings',
'ui_patterns_library',
];

/**
* Tests the copy to clipboard behavior in the copyright overlay.
*/
public function testCopyToClipboard(): void {
$this->drupalLogin($this->drupalCreateUser([], NULL, TRUE));

$this->drupalGet('/patterns/copyright_overlay');

// Mock the clipboard API.
$this->getSession()->executeScript(<<<JS
navigator.clipboard = {
writeText: function(text) {
// Store the copied text in a variable.
window.copiedText = text;
return Promise.resolve();
}
};
JS);

$elements = $this->getSession()->getPage()->findAll('css', '.copyright-overlay');

$this->assertCopyrightCopiedToClipboard($elements['0'], '© Copyright ipsum amet John Doe on Doe Images.');
$this->assertCopyrightCopiedToClipboard($elements['1'], '© Second copyright element. Suspendisse vel mauris vitae ipsum blandit condimentum ut eget quam.');
}

/**
* Asserts that the text in the element corresponds to the clipboard.
*
* @param \Behat\Mink\Element\NodeElement $element
* The copyright element.
* @param string $expected
* The expected result.
*/
protected function assertCopyrightCopiedToClipboard(NodeElement $element, string $expected): void {
$assert_session = $this->assertSession();

$assert_session->elementExists('css', '.copyright-trigger', $element)->click();
$modal = $assert_session->waitForElementVisible('css', '.modal.show');

$assert_session->elementExists('css', '[data-copy-target]', $modal)->click();

$actual = $this->getSession()->evaluateScript('return window.copiedText;');

$this->assertEquals($expected, $actual);
}

}
1 change: 1 addition & 0 deletions tests/src/Kernel/MarkupRenderingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class MarkupRenderingTest extends KernelTestBase implements FormInterface {
'card_layout',
'carousel',
'columns',
'copyright_overlay',
'content_banner',
'date_block',
'description_list',
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/ValueObject/ImageValueObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Drupal\Tests\oe_bootstrap_theme\Kernel\ValueObject;

use Drupal\Tests\oe_bootstrap_theme\Kernel\AbstractKernelTestBase;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
use Drupal\oe_bootstrap_theme\ValueObject\ImageValueObject;
use Drupal\Tests\oe_bootstrap_theme\Kernel\AbstractKernelTestBase;

/**
* Test image value object with image field type. Extracted from oe_theme.
Expand Down
Loading