Skip to content

Commit

Permalink
EWPP-3866: Update available flag options for paragraphs.
Browse files Browse the repository at this point in the history
  • Loading branch information
22Alexandra authored and nagyad committed Jan 11, 2024
1 parent 4fbef7c commit 2407d2b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 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 @@ -47,3 +47,7 @@ services:
oe_theme_helper.external_links:
class: Drupal\oe_theme_helper\ExternalLinks
arguments: ['@config.factory']
oe_theme_helper.flag_options_subscriber:
class: Drupal\oe_theme_helper\EventSubscriber\FlagOptionsEventSubscriber
tags:
- { name: event_subscriber }
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types = 1);

namespace Drupal\oe_theme_helper\EventSubscriber;

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

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

use StringTranslationTrait;

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

/**
* Alter the list of allowed flag icons.
*
* @param \Drupal\oe_paragraphs\Event\FlagOptionsEvent $event
* The event.
*/
public function alterFlagOptions(FlagOptionsEvent $event): void {
$options = $event->getFlagOptions();
$options['albania'] = $this->t('Albania');
$options['bosnia-and-herzegovina'] = $this->t('Bosnia and Herzegovina');
$options['georgia'] = $this->t('Georgia');
$options['iceland'] = $this->t('Iceland');
$options['moldova'] = $this->t('Moldova');
$options['montenegro'] = $this->t('Montenegro');
$options['north-macedonia'] = $this->t('North Macedonia');
$options['norway'] = $this->t('Norway');
$options['serbia'] = $this->t('Serbia');
$options['switzerland'] = $this->t('Switzerland');
$options['turkey'] = $this->t('Turkey');
$options['ukraine'] = $this->t('Ukraine');
ksort($options);
$event->setFlagOptions($options);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testIllustrationListFlagsRendering(): void {

$paragraph = Paragraph::create([
'type' => 'oe_illustration_item_flag',
'field_oe_flag' => 'finland',
'field_oe_flag' => 'north-macedonia',
]);
$paragraph->save();
$items[] = $paragraph;
Expand Down Expand Up @@ -135,7 +135,7 @@ public function testIllustrationListFlagsRendering(): void {
'icon' => 'france',
'value' => 'Highlighted Term 3',
], [
'icon' => 'finland',
'icon' => 'north-macedonia',
],
],
'centered' => FALSE,
Expand Down Expand Up @@ -164,7 +164,7 @@ public function testIllustrationListFlagsRendering(): void {
'icon' => 'france-square',
'value' => 'Highlighted Term 3',
], [
'icon' => 'finland-square',
'icon' => 'north-macedonia-square',
],
],
];
Expand Down

0 comments on commit 2407d2b

Please sign in to comment.