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 17, 2023
1 parent 5729b07 commit 0a7bb54
Show file tree
Hide file tree
Showing 3 changed files with 58 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,40 @@
<?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;

/**
* Event subscriber to alter the list of allowed paragraph icons.
*/
class IconOptionsEventSubscriber implements EventSubscriberInterface {

use StringTranslationTrait;

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

/**
* Alter the list of allowed paragraph icons.
*
* @param \Drupal\oe_paragraphs\Event\IconOptionsEvent $event
* The event.
*/
public function alterIconOptions(IconOptionsEvent $event): void {
$options = $event->getIconOptions();
$options['log-in'] = $this->t('Log in');
$options['logged-in'] = $this->t('Logged in');
$event->setIconOptions($options);
}

}
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 0a7bb54

Please sign in to comment.