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-1657: Country flag in content type detail page. #181

Open
wants to merge 16 commits into
base: 1.x
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion bcl-builder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@ module.exports = {
},
},
],
copy: []
copy: [
{
from: ["node_modules/@openeuropa/bcl-theme-default/icons/world-flags/4x3/*.svg"],
to: path.resolve(outputFolder, "assets/icons/world-flags"),
options: { up: true },
},
]
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,25 @@
namespace Drupal\Tests\oe_whitelabel_contact_forms\Kernel;

use Drupal\contact\Entity\ContactForm;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\oe_whitelabel\Kernel\AbstractKernelTestBase;
use Drupal\Tests\oe_whitelabel\PatternAssertions\DescriptionListAssert;
use Drupal\Tests\sparql_entity_storage\Traits\SparqlConnectionTrait;
use Symfony\Component\DomCrawler\Crawler;

/**
* Tests that our contact forms renders with right markup.
*/
class ContactFormRenderTest extends KernelTestBase {
class ContactFormRenderTest extends AbstractKernelTestBase {

use SparqlConnectionTrait;

/**
* {@inheritdoc}
*/
protected static $modules = [
'oe_bootstrap_theme_helper',
'ui_patterns',
'ui_patterns_library',
'path',
'path_alias',
'options',
'user',
'system',
'telephone',
'contact',
'contact_storage',
Expand All @@ -45,16 +40,9 @@ class ContactFormRenderTest extends KernelTestBase {
protected function setUp(): void {
parent::setUp();

\Drupal::service('theme_installer')->install(['oe_whitelabel']);
$this->installEntitySchema('path_alias');
$this->installEntitySchema('contact_message');
$this->installEntitySchema('user');
$this->installSchema('system', 'sequences');

\Drupal::configFactory()
->getEditable('system.theme')
->set('default', 'oe_whitelabel')
->save();
$this->setUpSparql();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ content:
label: hidden
settings:
delimiter: ', '
properties: { }
show_country_flag: true
third_party_settings: { }
weight: 2
region: content
Expand All @@ -71,4 +73,5 @@ hidden:
oe_contact_url: true
oe_logo: true
oe_website: true
search_api_excerpt: true
status: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
langcode: en
status: true
dependencies:
config:
- field.field.oe_organisation.oe_stakeholder.oe_acronym
- field.field.oe_organisation.oe_stakeholder.oe_address
- field.field.oe_organisation.oe_stakeholder.oe_contact_url
- field.field.oe_organisation.oe_stakeholder.oe_logo
- field.field.oe_organisation.oe_stakeholder.oe_website
- oe_content_entity_organisation.oe_organisation_type.oe_stakeholder
module:
- address
- link
id: oe_organisation.oe_stakeholder.default
targetEntityType: oe_organisation
bundle: oe_stakeholder
mode: default
content:
created:
type: timestamp
label: hidden
settings:
date_format: medium
custom_date_format: ''
timezone: ''
third_party_settings: { }
weight: 0
region: content
name:
type: string
label: hidden
settings:
link_to_entity: false
third_party_settings: { }
weight: -5
region: content
oe_acronym:
type: string
label: above
settings:
link_to_entity: false
third_party_settings: { }
weight: 1
region: content
oe_address:
type: address_default
label: above
settings: { }
third_party_settings: { }
weight: 3
region: content
oe_contact_url:
type: link
label: above
settings:
trim_length: 80
url_only: false
url_plain: false
rel: ''
target: ''
third_party_settings: { }
weight: 5
region: content
oe_logo:
type: entity_reference_entity_view
label: above
settings:
view_mode: default
link: false
third_party_settings: { }
weight: 2
region: content
oe_website:
type: link
label: above
settings:
trim_length: 80
url_only: false
url_plain: false
rel: ''
target: ''
third_party_settings: { }
weight: 4
region: content
hidden:
langcode: true
search_api_excerpt: true
status: true
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function oe_whitelabel_extra_project_install($is_syncing): void {
'core.entity_form_display.node.oe_project.default',
'core.entity_form_display.oe_organisation.oe_cx_project_stakeholder.default',
'core.entity_view_display.oe_organisation.oe_cx_project_stakeholder.default',
'core.entity_view_display.oe_organisation.oe_stakeholder.default',
];

ConfigImporter::importMultiple('module', 'oe_whitelabel_extra_project', '/config/overrides/', $configs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,25 @@ function oe_whitelabel_extra_project_post_update_00001(): void {
];
ConfigImporter::importMultiple('module', 'oe_whitelabel_extra_project', '/config/post_updates/00001_decimal_budget_fields', $configs, TRUE);
}

/**
* Enable the country flag rendering in project organisations.
*/
function oe_whitelabel_extra_project_post_update_00002(&$sandbox) {
$view_display_ids = [
'oe_organisation.oe_cx_project_stakeholder.default',
'oe_organisation.oe_stakeholder.default',
];

/** @var \Drupal\Core\Entity\Entity\EntityViewDisplay[] $view_displays */
$view_displays = \Drupal::entityTypeManager()->getStorage('entity_view_display')->loadMultiple($view_display_ids);
foreach ($view_displays as $view_display) {
$component = $view_display->getComponent('oe_address');
if ($component === NULL) {
continue;
}

$component['settings']['show_country_flag'] = TRUE;
$view_display->setComponent('oe_address', $component)->save();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ field.formatter.settings.oe_whitelabel_helper_address_inline:
sequence:
type: boolean
label: 'Properties'
show_country_flag:
type: boolean
label: 'Show a country flag together with the address.'
condition.plugin.oe_whitelabel_helper_current_component_library:
type: condition.plugin
mapping:
Expand Down
26 changes: 26 additions & 0 deletions modules/oe_whitelabel_helper/oe_whitelabel_helper.module
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ function oe_whitelabel_helper_theme($existing, $type, $theme, $path) {
'address' => NULL,
'address_items' => [],
'address_delimiter' => NULL,
'country_flag' => NULL,
],
],
'oe_whitelabel_helper_country_flag' => [
'variables' => [
'country_code' => NULL,
'attributes' => [],
],
],
'oe_corporate_blocks_neutral_footer' => [
Expand Down Expand Up @@ -102,3 +109,22 @@ function oe_whitelabel_helper_requirements_alter(array &$requirements): void {
];
}
}

/**
* Default preprocess function for oe_whitelabel_helper_country_flag.
*
* @param array $variables
* The variables array.
*/
function template_preprocess_oe_whitelabel_helper_country_flag(array &$variables): void {
$theme_extension_list = \Drupal::service('extension.list.theme');

$variables['attributes']['class'][] = 'icon--fluid';

$image_uri = $theme_extension_list->getPath('oe_whitelabel') . '/assets/icons/world-flags/' . strtolower($variables['country_code']) . '.svg';
$variables['image'] = [
'#theme' => 'image__country_flag',
'#uri' => $image_uri,
'#attributes' => $variables['attributes'],
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static function defaultSettings() {
return [
'delimiter' => ', ',
'properties' => [],
'show_country_flag' => FALSE,
];
}

Expand All @@ -48,14 +49,18 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
'#description' => $this->t('Specify delimiter between address items.'),
'#required' => TRUE,
];

$form['properties'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Properties'),
'#default_value' => $this->getActiveProperties(),
'#description' => $this->t('Which properties should be displayed. Leave empty for all.'),
'#options' => $this->getPropertiesDisplayOptions(),
];
$form['show_country_flag'] = [
'#type' => 'checkbox',
'#title' => $this->t('Show country flag'),
'#default_value' => $this->getSetting('show_country_flag'),
];

return $form;
}
Expand All @@ -64,14 +69,20 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function settingsSummary() {
return [
$summary = [
$this->t('Delimiter: @delimiter', [
'@delimiter' => $this->getSetting('delimiter'),
]),
$this->t('Properties: @properties', [
'@properties' => implode(', ', $this->getActiveProperties()),
]),
];

if ($this->getSetting('show_country_flag')) {
$summary[] = $this->t('Show country flag');
}

return $summary;
}

/**
Expand Down Expand Up @@ -125,7 +136,7 @@ protected function viewElement(AddressInterface $address, $langcode) {

$items = $this->extractAddressItems($format_string, $address_elements);

return [
$build = [
'#theme' => 'oe_whitelabel_helper_address_inline',
'#address' => $address,
'#address_items' => $items,
Expand All @@ -136,6 +147,19 @@ protected function viewElement(AddressInterface $address, $langcode) {
],
],
];

if ($this->getSetting('show_country_flag')) {
$build['#country_flag'] = [
'#theme' => 'oe_whitelabel_helper_country_flag',
'#country_code' => $country_code,
'#attributes' => [
'class' => ['me-2'],
'alt' => $countries[$country_code],
],
];
}

return $build;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
* - address: Address object.
* - address_items: Address items.
* - address_delimiter: Delimiter between address items.
* - country_flag: The country address flag. Optional.
*
* @ingroup themeable
*/
#}
<span translate="no">
{{ address_items|join(address_delimiter) }}
<span translate="no" class="d-flex align-items-center">
{{ country_flag }} {{ address_items|join(address_delimiter) }}
</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{#
/**
* @file
* Default theme implementation for a country flag image.
*
* Available variables:
* - country_code: The ISO 3166-1 alpha-2 code of the country.
* - attributes: HTML attributes to be added to the image.
* - image: The flag image render array.
*
* @see template_preprocess_oe_whitelabel_helper_country_flag()
*
* @ingroup themeable
*/
#}
{% apply spaceless %}
{{ image }}
{% endapply %}
Loading