From f3adb60edbdc9ca0524b13b9f88ad1df1a453aca Mon Sep 17 00:00:00 2001
From: Abel Santos <abel.santos.corral@gmail.com>
Date: Mon, 13 Sep 2021 17:00:42 +0200
Subject: [PATCH] OEL-452: Add eu/non eu support at twig and theme.

---
 oe_whitelabel.theme                           | 21 ++++++++++----
 .../patterns/modal/modal-language.html.twig   | 28 +++++++++++++++++--
 2 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/oe_whitelabel.theme b/oe_whitelabel.theme
index 3aa61595..c21637cb 100644
--- a/oe_whitelabel.theme
+++ b/oe_whitelabel.theme
@@ -11,6 +11,8 @@ declare(strict_types = 1);
  * Implements hook__preprocess_links__language_block().
  */
 function oe_whitelabel_preprocess_links__language_block(&$variables) {
+  /** @var \Drupal\Core\Language\LanguageInterface[] $original_languages */
+  $original_languages = \Drupal::service('language_manager')->getNativeLanguages();
   $currentLanguage = \Drupal::languageManager()->getCurrentLanguage()->getName();
   $variables['language']['link'] = [
     'label' => $currentLanguage,
@@ -18,13 +20,21 @@ function oe_whitelabel_preprocess_links__language_block(&$variables) {
     'target' => 'languageModal',
   ];
 
-  foreach ($variables['links'] as $link => $values) {
-    if ($link !== $currentLanguage) {
-      $links[$link] = $values['link']['#title'];
+  $eu_links = [];
+  $non_eu_links = [];
+  foreach ($original_languages as $language) {
+    if ($language->getId() !== $currentLanguage) {
+      if ($language->getThirdPartySetting('oe_multilingual', 'category') === 'eu') {
+        $eu_links[$language->getId()] = $language->getName();
+      }
+      else {
+        $non_eu_links[$language->getId()] = $language->getName();
+      }
+      $links[$language->getId()] = $language->getName();
     }
   }
+
   unset($variables['links']);
-  // print_r($links);
   $variables['language']['modal'] = [
     'id' => 'languageModal',
     'size' => 'fullscreen',
@@ -32,7 +42,8 @@ function oe_whitelabel_preprocess_links__language_block(&$variables) {
       'title' => t('Select your language'),
       'label' => t('Close'),
     ],
-    'links' => $links,
+    'eu_links' => $eu_links,
+    'non_eu_links' => $non_eu_links,
     'footer' => [
       'label' => t('Close'),
     ],
diff --git a/templates/patterns/modal/modal-language.html.twig b/templates/patterns/modal/modal-language.html.twig
index deda0ebd..bd56b9bd 100644
--- a/templates/patterns/modal/modal-language.html.twig
+++ b/templates/patterns/modal/modal-language.html.twig
@@ -20,7 +20,7 @@
   {% endset %}
 {% endif %}
 
-{% if links %}
+{% if eu_links or non_eu_links %}
   {% set _body %}
     <div class="container">
       <div class="row">
@@ -29,8 +29,8 @@
         </div>
       </div>
       <div class="row">
-      {% set _number_items = (links|length / 2) %}
-      {% for link in links|batch(_number_items) %}
+      {% set _number_items = (eu_links|length / 2) %}
+      {% for link in eu_links|batch(_number_items) %}
         {% if loop.index % 2 == 0 %}
           <div class="col col-lg-4 offset-lg-2">
         {% else %}
@@ -44,6 +44,28 @@
           </div>
       {% endfor %}
       </div>
+      <div class="row">
+        <div class="col col-lg-8 offset-lg-2">
+          <h5 class="oe-language__title">EU non-official languages</h5>
+        </div>
+      </div>
+      <div class="row">
+      {% set _number_items = (non_eu_links|length / 2) %}
+      {% for link in non_eu_links|batch(_number_items) %}
+        {% if loop.index % 2 == 0 %}
+          <div class="col col-lg-4 offset-lg-2">
+        {% else %}
+          <div class="col col-lg-4">
+        {% endif %}
+            <div class="oe-language__list">
+              {% for id, name in link %}
+                <a href="#" class="oe-language__item">{{ name }}</a>
+              {% endfor %}
+            </div>
+          </div>
+      {% endfor %}
+      </div>
+    </div>
   {% endset %}
 {% endif %}
 
-- 
GitLab