Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit b1225dc6 authored by escuriola's avatar escuriola
Browse files

OEL-1160: Add page branding suggestion and preprocess variables.

parent a96ec435
No related branches found
No related tags found
1 merge request!71OEL-1160: Header refactor.
......@@ -8,6 +8,7 @@
declare(strict_types = 1);
use Drupal\Core\Form\FormStateInterface;
use Drupal\oe_whitelabel_helper\EuropeanUnionLanguages;
/**
* Implements hook__preprocess_links__language_block().
......@@ -105,6 +106,7 @@ function oe_whitelabel_form_system_theme_settings_alter(&$form, FormStateInterfa
'#type' => 'select',
'#title' => t('Component library'),
'#options' => [
'neutral' => t('Neutral'),
'ec' => t('European Commission'),
'eu' => t('European Union'),
],
......@@ -129,4 +131,73 @@ function oe_whitelabel_form_system_theme_settings_alter(&$form, FormStateInterfa
function oe_whitelabel_preprocess(&$variables) {
$variables['bcl_component_library'] = theme_get_setting('component_library') ?? 'eu';
$variables['bcl_header_style'] = theme_get_setting('header_style') ?? 'standard';
$variables['current_language_id'] = \Drupal::languageManager()->getCurrentLanguage()->getId();
$variables['bcl_logo_path'] = base_path() . drupal_get_path('theme', 'oe_bootstrap_theme') . '/assets/logos/';
}
/**
* Implements hook_preprocess_page().
*/
function oe_whitelabel_preprocess_page(&$variables) {
$site_config = \Drupal::config('system.site');
$variables['site_name'] = $site_config->get('name');
$variables['project_logo'] = [
'path' => file_url_transform_relative(file_create_url(theme_get_setting('logo.url'))),
'alt' => $site_config->get('name'),
];
}
/**
* Implements template_preprocess_block__system_branding_block().
*/
function oe_whitelabel_preprocess_block__system_branding_block(&$variables) {
if ($variables['bcl_component_library'] === 'ec') {
$variables['logo_aria_label'] = t('Home') . ' - ' . t('European Commission');
$variables['site_logo_alt'] = t('European Commission logo');
$variables['site_logo_title'] = t('European Commission');
$site_logo_href = 'https://ec.europa.eu/info';
}
elseif ($variables['bcl_component_library'] === 'eu') {
$variables['logo_aria_label'] = t('Home') . ' - ' . t('European Union');
$variables['site_logo_alt'] = t('European Union flag');
$variables['site_logo_title'] = t('European Union');
$site_logo_href = 'https://european-union.europa.eu';
}
else {
$variables['logo_aria_label'] = t('Home');
$variables['site_logo_alt'] = t('Home logo');
$variables['site_logo_title'] = t('Home');
$site_logo_href = '<front>';
}
// Provide correct icon for non-eu languages.
$language_code = \Drupal::languageManager()->getCurrentLanguage()->getId();
if (!EuropeanUnionLanguages::hasLanguage($language_code)) {
if ($language_code === 'nb') {
// Set correct icon for Norwegian language.
$variables['current_language_id'] = 'no';
}
else {
// Check whether ECL provides a logo for the language.
$ecl_logo = DRUPAL_ROOT . '/' . drupal_get_path('theme', 'oe_theme') . '/dist/' . $variables['ecl_component_library'] . '/images/logo/';
$ecl_logo .= $variables['ecl_component_library'] === 'eu' ? 'standard-version/positive/' : '';
$ecl_logo .= 'logo-' . $variables['ecl_component_library'] . '--' . $language_code . '.svg';
if (!file_exists($ecl_logo)) {
// Provide fallback "en" icon if language logo doesn't exist.
$variables['current_language_id'] = 'en';
}
}
}
else {
$site_logo_href .= '/index_' . EuropeanUnionLanguages::getInternalLanguageCode($variables['current_language_id']);
}
$variables['site_logo_href'] = $site_logo_href;
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function oe_whitelabel_theme_suggestions_page_alter(array &$suggestions, array $variables): void {
// Set branding template in the beginning as more common.
array_unshift($suggestions, 'page__bcl_branding');
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment