Merge branch 'language-switcher-footer' into 'master'

Language switcher footer

See merge request agaric/sites/agaric-com!54
This commit is contained in:
mlncn 2019-01-22 18:32:20 +00:00
commit 474ca14f5f
7 changed files with 168 additions and 31 deletions

View file

@ -21,6 +21,7 @@
"drupal/core": "^8.6.2", "drupal/core": "^8.6.2",
"drupal/customerror": "1.x-dev", "drupal/customerror": "1.x-dev",
"drupal/diff": "^1.0@RC", "drupal/diff": "^1.0@RC",
"drupal/dropdown_language": "^2.2",
"drupal/drutopia_core": "1.x-dev", "drupal/drutopia_core": "1.x-dev",
"drupal/google_analytics": "^2.3", "drupal/google_analytics": "^2.3",
"drupal/honeypot": "^1.29", "drupal/honeypot": "^1.29",

67
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "788dcf2c1028c477fe97c294b439dbba", "content-hash": "f6b711848cb356b08282c888a7c34e09",
"packages": [ "packages": [
{ {
"name": "asm89/stack-cors", "name": "asm89/stack-cors",
@ -2346,7 +2346,7 @@
}, },
"drupal": { "drupal": {
"version": "8.x-1.25", "version": "8.x-1.25",
"datestamp": "1542915384", "datestamp": "1542915180",
"security-coverage": { "security-coverage": {
"status": "covered", "status": "covered",
"message": "Covered by Drupal's security advisory policy" "message": "Covered by Drupal's security advisory policy"
@ -2417,7 +2417,7 @@
}, },
"drupal": { "drupal": {
"version": "8.x-1.25", "version": "8.x-1.25",
"datestamp": "1542915384", "datestamp": "1542915180",
"security-coverage": { "security-coverage": {
"status": "covered", "status": "covered",
"message": "Covered by Drupal's security advisory policy" "message": "Covered by Drupal's security advisory policy"
@ -4076,7 +4076,7 @@
}, },
"drupal": { "drupal": {
"version": "8.x-1.x-dev", "version": "8.x-1.x-dev",
"datestamp": "1542578580", "datestamp": "1542572880",
"security-coverage": { "security-coverage": {
"status": "not-covered", "status": "not-covered",
"message": "Dev releases are not covered by Drupal security advisories." "message": "Dev releases are not covered by Drupal security advisories."
@ -4277,6 +4277,53 @@
"issues": "https://www.drupal.org/project/issues/diff" "issues": "https://www.drupal.org/project/issues/diff"
} }
}, },
{
"name": "drupal/dropdown_language",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://git.drupal.org/project/dropdown_language",
"reference": "8.x-2.2"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/dropdown_language-8.x-2.2.zip",
"reference": "8.x-2.2",
"shasum": "78e9c73fe7414114eaf4884e23eac671c74e302f"
},
"require": {
"drupal/core": "*"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-2.x": "2.x-dev"
},
"drupal": {
"version": "8.x-2.2",
"datestamp": "1540134181",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
}
},
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0-or-later"
],
"authors": [
{
"name": "SKAUGHT",
"homepage": "https://www.drupal.org/user/297907"
}
],
"description": "Provides a block with a Dropdown Language Switcher",
"homepage": "https://www.drupal.org/project/dropdown_language",
"support": {
"source": "http://cgit.drupalcode.org/dropdown_language"
}
},
{ {
"name": "drupal/drutopia_action", "name": "drupal/drutopia_action",
"version": "1.0.0-beta1", "version": "1.0.0-beta1",
@ -6541,6 +6588,10 @@
"name": "golddragon007", "name": "golddragon007",
"homepage": "https://www.drupal.org/user/2723471" "homepage": "https://www.drupal.org/user/2723471"
}, },
{
"name": "james.williams",
"homepage": "https://www.drupal.org/user/592268"
},
{ {
"name": "lbesenyei", "name": "lbesenyei",
"homepage": "https://www.drupal.org/user/2626013" "homepage": "https://www.drupal.org/user/2626013"
@ -6597,10 +6648,6 @@
{ {
"name": "kristiaanvandeneynde", "name": "kristiaanvandeneynde",
"homepage": "https://www.drupal.org/user/1345130" "homepage": "https://www.drupal.org/user/1345130"
},
{
"name": "ronaldtebrake",
"homepage": "https://www.drupal.org/user/2314038"
} }
], ],
"description": "Enables Group functionality for the Node module", "description": "Enables Group functionality for the Node module",
@ -6704,10 +6751,6 @@
{ {
"name": "kristiaanvandeneynde", "name": "kristiaanvandeneynde",
"homepage": "https://www.drupal.org/user/1345130" "homepage": "https://www.drupal.org/user/1345130"
},
{
"name": "ronaldtebrake",
"homepage": "https://www.drupal.org/user/2314038"
} }
], ],
"description": "This module allows you to group users, content and other entities", "description": "This module allows you to group users, content and other entities",

View file

@ -0,0 +1,27 @@
uuid: cddd6272-7a22-4110-862c-338686afc1c1
langcode: en
status: true
dependencies:
module:
- block_visibility_groups
- dropdown_language
theme:
- agarica
id: languageswitcher
theme: agarica
region: footer
weight: 0
provider: null
plugin: 'dropdown_language:language_interface'
settings:
id: 'dropdown_language:language_interface'
label: 'Language:'
provider: dropdown_language
label_display: visible
labels: null
visibility:
condition_group:
id: condition_group
negate: false
block_visibility_group: ''
context_mapping: { }

View file

@ -0,0 +1,19 @@
uuid: 1a7bd96c-ab4a-4a86-a541-b9610491c292
langcode: en
status: true
dependencies:
module:
- dropdown_language
id: config_sync.module.dropdown_language
snapshotSet: config_sync
extensionType: module
extensionName: dropdown_language
items:
-
collection: ''
name: dropdown_language.setting
data:
wrapper: true
display_language_id: 0
filter_untranslated: 0
always_show_block: 0

View file

@ -40,6 +40,7 @@ module:
dblog: 0 dblog: 0
default_content: 0 default_content: 0
diff: 0 diff: 0
dropdown_language: 0
drutopia_action: 0 drutopia_action: 0
drutopia_article: 0 drutopia_article: 0
drutopia_blog: 0 drutopia_blog: 0

View file

@ -0,0 +1,6 @@
wrapper: false
display_language_id: 2
filter_untranslated: 0
always_show_block: 0
_core:
default_config_hash: xbqiqGnFfv7G00sewxA46T8PO-uo8uvWhDSIFyR1Fhk

View file

@ -1,25 +1,65 @@
<?php <?php
use \Drupal\Core\Url; use Drupal\block\Entity\Block;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
/** /**
* Implements hook_preprocess_block__system_menu_block__main(). * Implements hook_preprocess_region__footer().
*/ */
function agarica_preprocess_block__system_menu_block__main(&$variables) { function agarica_preprocess_region__footer(&$variables) {
$pathMatcher = \Drupal::service('path.matcher'); $block = Block::load('languageswitcher');
$languageManager = \Drupal::service('language_manager'); $block_content = \Drupal::entityTypeManager()
$route_name = $pathMatcher->isFrontPage() ? '<front>' : '<current>'; ->getViewBuilder('block')
$type = 'language_interface'; ->view($block);
$language_links = $languageManager->getLanguageSwitchLinks($type, Url::fromRoute($route_name)); $variables['language_switcher'] = $block_content;
$variables['language'] = []; $variables['language_switcher_link'] = agarica_languague_switch_link();
foreach ($language_links->links as $langcode => $link) {
$language_links->links[$langcode]['attributes']['class'][] = 'navbar-item';
$language_links->links[$langcode]['title'] = $langcode;
} }
$variables['language'] = [
'#theme' => 'links__language_block',
'#links' => $language_links->links,
'#set_active_class' => TRUE,
];
/**
* Provides a link to switch to another language.
*/
function agarica_languague_switch_link() {
$derivative_id = 'language_interface';
$route = \Drupal::getContainer()->get('path.matcher')->isFrontPage() ? '<front>' : '<current>';
$current_language = \Drupal::languageManager()->getCurrentLanguage($derivative_id)->getId();
$links = \Drupal::languageManager()->getLanguageSwitchLinks($derivative_id, Url::fromRoute($route))->links;
$links['en']['title'] = 'Browse this site in English';
$links['es']['title'] = 'Consulta este sitio en Español';
$lid = ($current_language == 'en') ? 'es' : 'en';
// Remove current language from the links
unset($links[$current_language]);
// Check if the current path display an entity.
$entity = FALSE;
foreach (\Drupal::routeMatch()->getParameters() as $param) {
if ($param instanceof EntityInterface) {
$entity[] = $param;
}
}
// Remove links if the content hasnt' been translated yet.
if ($entity) {
$has_translation = (method_exists($entity[0], 'getTranslationStatus')) ? $entity[0]->getTranslationStatus($lid) : FALSE;
$this_translation = ($has_translation && method_exists($entity[0], 'getTranslation')) ? $entity[0]->getTranslation($lid) : FALSE;
$access_translation = ($this_translation && method_exists($this_translation, 'access') && $this_translation->access('view')) ? TRUE : FALSE;
if (!$this_translation || !$access_translation || $current_language == $lid) {
unset($links[$lid]);
}
}
$links_render_array = [];
// Transform the links to arrays that can be renderer.
foreach ($links as $language => $link) {
$links_render_array[] = [
'#type' => 'link',
'#url' => $link['url'],
'#title' => $link['title'],
'#options' => [
'language' => $link['language'],
],
];
}
return $links_render_array;
} }