Skip to content

Commit

Permalink
EWPP-3102: Allow 2 new icons to be used in field_oe_icon of paragraphs.
Browse files Browse the repository at this point in the history
  • Loading branch information
22Alexandra committed Feb 13, 2023
1 parent 53d13d1 commit 8636481
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 2 deletions.
4 changes: 4 additions & 0 deletions modules/oe_theme_helper/oe_theme_helper.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ services:
arguments: ['@current_route_match', '@entity_type.manager', '@entity.repository']
tags:
- { name: event_subscriber }
oe_theme_helper.icon_options_subscriber:
class: Drupal\oe_theme_helper\EventSubscriber\IconOptionsEventSubscriber
tags:
- { name: event_subscriber }
plugin.manager.oe_theme.media_data_extractor:
class: Drupal\oe_theme_helper\MediaDataExtractorPluginManager
parent: default_plugin_manager
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

declare(strict_types = 1);

namespace Drupal\oe_theme_helper\EventSubscriber;

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\oe_paragraphs\Event\IconOptionsEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Provides a list of allowed icons.
*/
class IconOptionsEventSubscriber implements EventSubscriberInterface {

use StringTranslationTrait;

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
IconOptionsEvent::class => 'getIconOptions',
];
}

/**
* Gets the icon options.
*
* @param \Drupal\oe_paragraphs\Event\IconOptionsEvent $event
* Allowed format event object.
*/
public function getIconOptions(IconOptionsEvent $event): void {
$event->setIconOptions([
'arrow-down' => $this->t('Arrow down'),
'external' => $this->t('External'),
'arrow-up' => $this->t('Arrow up'),
'audio' => $this->t('Audio'),
'book' => $this->t('Book'),
'breadcrumb' => $this->t('Breadcrumb'),
'brochure' => $this->t('Brochure'),
'budget' => $this->t('Budget'),
'calendar' => $this->t('Calendar'),
'camera' => $this->t('Camera'),
'check' => $this->t('Check'),
'close' => $this->t('Close'),
'close-dark' => $this->t('Close dark'),
'copy' => $this->t('Copy'),
'data' => $this->t('Data'),
'digital' => $this->t('Digital'),
'down' => $this->t('Down'),
'download' => $this->t('Download'),
'edit' => $this->t('Edit'),
'energy' => $this->t('Energy'),
'error' => $this->t('Error'),
'euro' => $this->t('Euro'),
'facebook' => $this->t('Facebook'),
'faq' => $this->t('Faq'),
'feedback' => $this->t('Feedback'),
'file' => $this->t('File'),
'generic-lang' => $this->t('Generic language'),
'global' => $this->t('Global'),
'googleplus' => $this->t('Google Plus (deprecated)'),
'growth' => $this->t('Growth'),
'image' => $this->t('Image'),
'in' => $this->t('In'),
'info' => $this->t('Info'),
'infographic' => $this->t('Infographic'),
'language' => $this->t('Language'),
'left' => $this->t('Left'),
'linkedin' => $this->t('LinkedIn'),
'livestreaming' => $this->t('Live streaming'),
'location' => $this->t('Location'),
'log-in' => $this->t('Log in'),
'logged-in' => $this->t('Logged in'),
'multiple-files' => $this->t('Multiple files'),
'organigram' => $this->t('Organigram'),
'package' => $this->t('Package'),
'presentation' => $this->t('Presentation'),
'regulation' => $this->t('Regulation'),
'right' => $this->t('Right'),
'rss' => $this->t('RSS'),
'search' => $this->t('Search'),
'share' => $this->t('Share'),
'slides' => $this->t('Slides (deprecated)'),
'spinner' => $this->t('Spinner'),
'spreadsheet' => $this->t('Spreadsheet'),
'success' => $this->t('Success'),
'tag-close' => $this->t('Tag close'),
'twitter' => $this->t('Twitter'),
'up' => $this->t('Up'),
'video' => $this->t('Video'),
'warning' => $this->t('Warning'),
]);
}

}
16 changes: 14 additions & 2 deletions tests/src/Kernel/Paragraphs/ParagraphsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,14 +612,16 @@ public function testContextualNavigation(): void {
* Test 'Facts and figures' paragraph rendering.
*/
public function testFactsFigures(): void {
// Create three Facts to be referenced from the Facts and figures paragraph.
// Create some Facts to be referenced from the Facts and figures paragraph.
$items = [];
$icons = [
1 => 'infographic',
2 => 'spreadsheet',
3 => 'digital',
4 => 'log-in',
5 => 'logged-in',
];
for ($i = 1; $i < 4; $i++) {
for ($i = 1; $i < 6; $i++) {
$paragraph = Paragraph::create([
'type' => 'oe_fact',
'field_oe_icon' => $icons[$i],
Expand Down Expand Up @@ -693,20 +695,30 @@ protected function assertFactsFigures(Crawler $crawler, string $component_librar
$this->assertCount(1, $crawler->filter("div.ecl-fact-figures__item:nth-child(1) svg.ecl-icon.ecl-icon--$fact_icon_size.ecl-fact-figures__icon"), $component_library);
$this->assertCount(1, $crawler->filter("div.ecl-fact-figures__item:nth-child(2) svg.ecl-icon.ecl-icon--$fact_icon_size.ecl-fact-figures__icon"));
$this->assertCount(1, $crawler->filter("div.ecl-fact-figures__item:nth-child(3) svg.ecl-icon.ecl-icon--$fact_icon_size.ecl-fact-figures__icon"));
$this->assertCount(1, $crawler->filter("div.ecl-fact-figures__item:nth-child(4) svg.ecl-icon.ecl-icon--$fact_icon_size.ecl-fact-figures__icon"));
$this->assertCount(1, $crawler->filter("div.ecl-fact-figures__item:nth-child(5) svg.ecl-icon.ecl-icon--$fact_icon_size.ecl-fact-figures__icon"));

$this->assertEquals('Facts and figures', trim($crawler->filter('h2.ecl-u-type-heading-2')->text()));
$this->assertEquals("<use xlink:href=\"/themes/custom/oe_theme/dist/$component_library/images/icons/sprites/icons.svg#infographic\"></use>", $crawler->filter("div.ecl-fact-figures__item:nth-child(1) svg.ecl-icon.ecl-icon--$fact_icon_size.ecl-fact-figures__icon")->html());
$this->assertEquals("<use xlink:href=\"/themes/custom/oe_theme/dist/$component_library/images/icons/sprites/icons.svg#spreadsheet\"></use>", $crawler->filter("div.ecl-fact-figures__item:nth-child(2) svg.ecl-icon.ecl-icon--$fact_icon_size.ecl-fact-figures__icon")->html());
$this->assertEquals("<use xlink:href=\"/themes/custom/oe_theme/dist/$component_library/images/icons/sprites/icons.svg#digital\"></use>", $crawler->filter("div.ecl-fact-figures__item:nth-child(3) svg.ecl-icon.ecl-icon--$fact_icon_size.ecl-fact-figures__icon")->html());
$this->assertEquals("<use xlink:href=\"/themes/custom/oe_theme/dist/$component_library/images/icons/sprites/icons.svg#log-in\"></use>", $crawler->filter("div.ecl-fact-figures__item:nth-child(4) svg.ecl-icon.ecl-icon--$fact_icon_size.ecl-fact-figures__icon")->html());
$this->assertEquals("<use xlink:href=\"/themes/custom/oe_theme/dist/$component_library/images/icons/sprites/icons.svg#logged-in\"></use>", $crawler->filter("div.ecl-fact-figures__item:nth-child(5) svg.ecl-icon.ecl-icon--$fact_icon_size.ecl-fact-figures__icon")->html());
$this->assertEquals('10 millions', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(1) div.ecl-fact-figures__value')->text()));
$this->assertEquals('20 millions', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(2) div.ecl-fact-figures__value')->text()));
$this->assertEquals('30 millions', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(3) div.ecl-fact-figures__value')->text()));
$this->assertEquals('40 millions', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(4) div.ecl-fact-figures__value')->text()));
$this->assertEquals('50 millions', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(5) div.ecl-fact-figures__value')->text()));
$this->assertEquals('Fact 1', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(1) div.ecl-fact-figures__title')->text()));
$this->assertEquals('Fact 2', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(2) div.ecl-fact-figures__title')->text()));
$this->assertEquals('Fact 3', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(3) div.ecl-fact-figures__title')->text()));
$this->assertEquals('Fact 4', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(4) div.ecl-fact-figures__title')->text()));
$this->assertEquals('Fact 5', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(5) div.ecl-fact-figures__title')->text()));
$this->assertEquals('Fact description 1', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(1) div.ecl-fact-figures__description')->text()));
$this->assertEquals('Fact description 2', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(2) div.ecl-fact-figures__description')->text()));
$this->assertEquals('Fact description 3', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(3) div.ecl-fact-figures__description')->text()));
$this->assertEquals('Fact description 4', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(4) div.ecl-fact-figures__description')->text()));
$this->assertEquals('Fact description 5', trim($crawler->filter('div.ecl-fact-figures__item:nth-child(5) div.ecl-fact-figures__description')->text()));

$link = $crawler->filter('div.ecl-fact-figures__view-all a.ecl-link.ecl-link--standalone.ecl-link--icon.ecl-link--icon-after.ecl-fact-figures__view-all-link');
$actual = $link->text();
Expand Down

0 comments on commit 8636481

Please sign in to comment.