Skip to content

Commit

Permalink
Merge pull request #81 from openeuropa/OEL-1147
Browse files Browse the repository at this point in the history
OEL-1147 - Footer.
  • Loading branch information
brummbar authored Mar 14, 2022
2 parents 50efe5b + 9d3aae1 commit 0777c70
Show file tree
Hide file tree
Showing 30 changed files with 572 additions and 454 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"openeuropa/oe_contact_forms": "~1.1",
"openeuropa/oe_corporate_blocks": "^4.4",
"openeuropa/oe_multilingual": "^1.9",
"openeuropa/oe_starter_content": "1.x-dev",
"openeuropa/oe_starter_content": "1.x-dev#5a4a77b",
"openeuropa/task-runner-drupal-project-symlink": "^1.0-beta5",
"phpspec/prophecy-phpunit": "^1 || ^2"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ settings:
label: 'EC Footer block'
provider: oe_corporate_blocks
label_display: '0'
visibility: { }
visibility:
oe_whitelabel_helper_current_component_library:
id: oe_whitelabel_helper_current_component_library
component_library: ec
negate: false
context_mapping: { }
24 changes: 24 additions & 0 deletions config/optional/block.block.oe_whitelabel_eu_corporate_footer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
langcode: en
status: true
dependencies:
module:
- oe_corporate_blocks
theme:
- oe_whitelabel
id: oe_whitelabel_eu_corporate_footer
theme: oe_whitelabel
region: footer
weight: 0
provider: null
plugin: oe_corporate_blocks_eu_footer
settings:
id: oe_corporate_blocks_eu_footer
label: 'EU Footer block'
provider: oe_corporate_blocks
label_display: '0'
visibility:
oe_whitelabel_helper_current_component_library:
id: oe_whitelabel_helper_current_component_library
component_library: eu
negate: false
context_mapping: { }
24 changes: 24 additions & 0 deletions config/optional/block.block.oe_whitelabel_neutral_footer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
langcode: en
status: true
dependencies:
module:
- oe_whitelabel_helper
theme:
- oe_whitelabel
id: oe_whitelabel_neutral_footer
theme: oe_whitelabel
region: footer
weight: 0
provider: null
plugin: oe_corporate_blocks_neutral_footer
settings:
id: oe_corporate_blocks_neutral_footer
label: 'Neutral Footer block'
provider: oe_whitelabel_helper
label_display: '0'
visibility:
oe_whitelabel_helper_current_component_library:
id: oe_whitelabel_helper_current_component_library
component_library: neutral
negate: false
context_mapping: { }
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ field.formatter.settings.oe_whitelabel_helper_address_inline:
delimiter:
type: string
label: 'Delimiter for address items.'
condition.plugin.oe_whitelabel_helper_current_component_library:
type: condition.plugin
mapping:
component_library:
type: string
1 change: 1 addition & 0 deletions modules/oe_whitelabel_helper/oe_whitelabel_helper.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ core_version_requirement: ^9.2

dependencies:
- oe_bootstrap_theme:oe_bootstrap_theme_helper
- openeuropa:oe_corporate_blocks

'interface translation project': oe_whitelabel_helper
9 changes: 9 additions & 0 deletions modules/oe_whitelabel_helper/oe_whitelabel_helper.module
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,14 @@ function oe_whitelabel_helper_theme($existing, $type, $theme, $path) {
'address_delimiter' => NULL,
],
],
'oe_corporate_blocks_neutral_footer' => [
'variables' => [
'corporate_footer' => [],
'site_specific_footer' => [],
],
'preprocess functions' => [
'oe_corporate_blocks_preprocess_set_site_owner',
],
],
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types = 1);

namespace Drupal\oe_whitelabel_helper\Plugin\Block;

use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\oe_corporate_blocks\Plugin\Block\FooterBlockBase;

/**
* Provides the Neutral footer block.
*
* @Block(
* id = "oe_corporate_blocks_neutral_footer",
* admin_label = @Translation("Neutral Footer block"),
* category = @Translation("Corporate blocks"),
* )
*/
class NeutralFooterBlock extends FooterBlockBase implements ContainerFactoryPluginInterface {

/**
* {@inheritdoc}
*/
public function build() {
$cache = new CacheableMetadata();
$cache->addCacheContexts(['languages:language_interface']);

$config = $this->configFactory->get('oe_corporate_blocks.ec_data.footer');
$cache->addCacheableDependency($config);

$build['#theme'] = 'oe_corporate_blocks_neutral_footer';

NestedArray::setValue($build, ['#corporate_footer', 'content_owner_details'], $config->get('content_owner_details'));

$this->setSiteSpecificFooter($build, $cache);

$cache->applyTo($build);

return $build;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

declare(strict_types = 1);

namespace Drupal\oe_whitelabel_helper\Plugin\Condition;

use Drupal\Core\Cache\Cache;
use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Theme\ThemeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Provides a configurable 'Current component library' condition.
*
* This condition checks if the current component library is equal to a given
* value.
*
* @Condition(
* id = "oe_whitelabel_helper_current_component_library",
* label = @Translation("Current component library")
* )
*/
class CurrentComponentLibraryCondition extends ConditionPluginBase implements ContainerFactoryPluginInterface {

/**
* The configuration factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;

/**
* The theme manager.
*
* @var \Drupal\Core\Theme\ThemeManagerInterface
*/
protected $themeManager;

/**
* Constructs a CurrentComponentLibraryCondition condition plugin.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory service.
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
* The theme manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, ThemeManagerInterface $theme_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configFactory = $config_factory;
$this->themeManager = $theme_manager;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('config.factory'),
$container->get('theme.manager')
);
}

/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'component_library' => '',
] + parent::defaultConfiguration();
}

/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// We allow for an empty value to be set. By doing that we make sure that
// no settings about this condition is actually saved in block visibility
// settings, unless the user explicitly sets one.
$form['component_library'] = [
'#type' => 'select',
'#title' => $this->t('Component library'),
'#options' => [
'' => $this->t('- Any -'),
'neutral' => $this->t('Neutral'),
'ec' => $this->t('European Commission'),
'eu' => $this->t('European Union'),
],
'#default_value' => $this->configuration['component_library'],
'#description' => t('Choose with which component library this condition should be met.'),
];
return parent::buildConfigurationForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['component_library'] = $form_state->getValue('component_library');
parent::submitConfigurationForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function evaluate() {
if (empty($this->configuration['component_library'])) {
return TRUE;
}
$theme_name = $this->themeManager->getActiveTheme()->getName();

$component_library = $this->configFactory->get($theme_name . '.settings')->get('component_library');
return $component_library === $this->configuration['component_library'];
}

/**
* {@inheritdoc}
*/
public function summary() {
if (empty($this->configuration['component_library'])) {
return $this->t('The current component library can be set to anything');
}

if ($this->isNegated()) {
return $this->t('The current component library is not @component_library', ['@component_library' => $this->configuration['component_library']]);
}

return $this->t('The current component library is @component_library', ['@component_library' => $this->configuration['component_library']]);
}

/**
* {@inheritdoc}
*/
public function getCacheTags() {
$theme_name = $this->themeManager->getActiveTheme()->getName();

return Cache::mergeTags(['config:' . $theme_name . '.settings'], parent::getCacheTags());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
use Drupal\oe_whitelabel_helper\EuropeanUnionLanguages;
use Drupal\Core\Url;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
Expand Down Expand Up @@ -122,6 +123,9 @@ public function bclFooterLinks(array $context, array $links): array {
$altered_links = [];

foreach ($links as $link) {
if ($link['href'] instanceof Url) {
$link['href'] = $link['href']->toString();
}
$altered_link = [
'label' => $link['label'],
'path' => $link['href'],
Expand Down Expand Up @@ -168,6 +172,8 @@ public function bclFooterLinks(array $context, array $links): array {
*
* @return array
* The block render array.
*
* @deprecated Use Twig Tweak instead.
*/
public function bclBlock(string $id, array $configuration = []): array {
$configuration += ['label_display' => 'hidden'];
Expand Down
2 changes: 1 addition & 1 deletion oe_whitelabel.theme
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function oe_whitelabel_form_system_theme_settings_alter(&$form, FormStateInterfa
'ec' => t('European Commission'),
'eu' => t('European Union'),
],
'#default_value' => theme_get_setting('component_library'),
'#default_value' => theme_get_setting('component_library') ?? 'neutral',
'#description' => t('Choose "European Commission" for websites hosted under the ec.europa.eu domain and "European Union" for websites hosted under the europa.eu domain.'),
];
$form['header_style'] = [
Expand Down
3 changes: 0 additions & 3 deletions templates/layouts/ec_footer_bottom_left.html.twig

This file was deleted.

7 changes: 0 additions & 7 deletions templates/layouts/ec_footer_bottom_middle.html.twig

This file was deleted.

7 changes: 0 additions & 7 deletions templates/layouts/ec_footer_bottom_right.html.twig

This file was deleted.

8 changes: 0 additions & 8 deletions templates/layouts/ec_footer_middle_row.html.twig

This file was deleted.

3 changes: 0 additions & 3 deletions templates/layouts/eu_footer_left.html.twig

This file was deleted.

22 changes: 0 additions & 22 deletions templates/layouts/eu_footer_middle.html.twig

This file was deleted.

8 changes: 0 additions & 8 deletions templates/layouts/eu_footer_right.html.twig

This file was deleted.

Loading

0 comments on commit 0777c70

Please sign in to comment.