From 79f952a0d584440fd9e8a90ca9adbab59d164ad8 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Sun, 5 Oct 2014 17:56:28 +0200
Subject: [PATCH] Issue #2329851 by lanchez, lauriii, Jolidog | davidhernandez:
 Move miscellaneous system classes from preprocess to templates.

---
 .../src/Controller/SystemController.php       |  6 ++---
 core/modules/system/system.admin.inc          | 27 ++++++++-----------
 .../templates/admin-block-content.html.twig   |  9 ++++++-
 .../system/templates/status-report.html.twig  |  4 +--
 .../templates/system-themes-page.html.twig    | 23 ++++++++++++++--
 .../templates/admin-block-content.html.twig   |  9 ++++++-
 6 files changed, 52 insertions(+), 26 deletions(-)

diff --git a/core/modules/system/src/Controller/SystemController.php b/core/modules/system/src/Controller/SystemController.php
index 43ab34ea59d2..5f2ca3f70e63 100644
--- a/core/modules/system/src/Controller/SystemController.php
+++ b/core/modules/system/src/Controller/SystemController.php
@@ -200,6 +200,7 @@ public function themesPage() {
         continue;
       }
       $theme->is_default = ($theme->getName() == $theme_default);
+      $theme->is_admin = ($theme->getName() == $admin_theme || ($theme->is_default && $admin_theme == '0'));
 
       // Identify theme screenshot.
       $theme->screenshot = NULL;
@@ -284,13 +285,10 @@ public function themesPage() {
 
       // Add notes to default and administration theme.
       $theme->notes = array();
-      $theme->classes = array();
       if ($theme->is_default) {
-        $theme->classes[] = 'theme-default';
         $theme->notes[] = $this->t('default theme');
       }
-      if ($theme->getName() == $admin_theme || ($theme->is_default && $admin_theme == '0')) {
-        $theme->classes[] = 'theme-admin';
+      if ($theme->is_admin) {
         $theme->notes[] = $this->t('admin theme');
       }
 
diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc
index a398857bff64..0231667703c2 100644
--- a/core/modules/system/system.admin.inc
+++ b/core/modules/system/system.admin.inc
@@ -53,14 +53,10 @@ function _system_is_incompatible(&$incompatible, $files, Extension $file) {
  */
 function template_preprocess_admin_block_content(&$variables) {
   if (!empty($variables['content'])) {
-    $compact = system_admin_compact_mode();
-    $variables['attributes'] = array('class' => array('admin-list'));
-    if ($compact) {
-      $variables['attributes']['class'][] = 'compact';
-    }
+    $variables['compact'] = system_admin_compact_mode();
     foreach ($variables['content'] as $key => $item) {
       $variables['content'][$key]['link'] = \Drupal::l($item['title'], $item['url']);
-      if (!$compact && isset($item['description'])) {
+      if (!$variables['compact'] && isset($item['description'])) {
         $variables['content'][$key]['description'] = Xss::filterAdmin($item['description']);
       }
       else {
@@ -164,19 +160,19 @@ function template_preprocess_status_report(&$variables) {
   $severities = array(
     REQUIREMENT_INFO => array(
       'title' => t('Info'),
-      'class' => 'info',
+      'status' => 'info',
     ),
     REQUIREMENT_OK => array(
       'title' => t('OK'),
-      'class' => 'ok',
+      'status' => 'ok',
     ),
     REQUIREMENT_WARNING => array(
       'title' => t('Warning'),
-      'class' => 'warning',
+      'status' => 'warning',
     ),
     REQUIREMENT_ERROR => array(
       'title' => t('Error'),
-      'class' => 'error',
+      'status' => 'error',
     ),
   );
 
@@ -194,8 +190,8 @@ function template_preprocess_status_report(&$variables) {
     else {
       $severity = $severities[REQUIREMENT_INFO];
     }
-    $variables['requirements'][$i]['severity_class'] = $severity['class'];
     $variables['requirements'][$i]['severity_title'] = $severity['title'];
+    $variables['requirements'][$i]['severity_status'] = $severity['status'];
   }
 }
 
@@ -375,7 +371,7 @@ function template_preprocess_system_themes_page(&$variables) {
     $theme_group['state'] = $state;
     $theme_group['title'] = $title;
     $theme_group['themes'] = array();
-    $theme_group['attributes'] = new Attribute(array('class' => array('system-themes-list', 'system-themes-list-' . $state, 'clearfix')));
+    $theme_group['attributes'] = new Attribute();
 
     foreach ($theme_groups[$state] as $theme) {
       $current_theme = array();
@@ -403,13 +399,12 @@ function template_preprocess_system_themes_page(&$variables) {
       // Localize the theme description.
       $current_theme['description'] = t($theme->info['description']);
 
-      // Style theme info.
-      $theme->classes[] = 'theme-selector';
-      $theme->classes[] = 'clearfix';
-      $current_theme['attributes'] = new Attribute(array('class' => $theme->classes));
+      $current_theme['attributes'] = new Attribute();
       $current_theme['name'] = $theme->info['name'];
       $current_theme['version'] = isset($theme->info['version']) ? $theme->info['version'] : '';
       $current_theme['notes'] = $theme->notes;
+      $current_theme['is_default'] = $theme->is_default;
+      $current_theme['is_admin'] = $theme->is_admin;
 
       // Make sure to provide feedback on compatibility.
       $current_theme['incompatible'] = '';
diff --git a/core/modules/system/templates/admin-block-content.html.twig b/core/modules/system/templates/admin-block-content.html.twig
index a49bf1011533..e70e565b71d8 100644
--- a/core/modules/system/templates/admin-block-content.html.twig
+++ b/core/modules/system/templates/admin-block-content.html.twig
@@ -9,14 +9,21 @@
  *   contain the keys 'title', 'link_path', and 'localized_options', which are
  *   passed to l(). A 'description' key may also be provided.
  * - attributes: HTML attributes to be added to the element.
+ * - compact: Boolean indicating whether compact mode is turned on or not.
  *
  * @see template_preprocess_admin_block_content()
  *
  * @ingroup themeable
  */
 #}
+{%
+  set classes = [
+    'admin-list',
+    compact ? 'compact',
+  ]
+%}
 {% if content %}
-  <dl{{ attributes }}>
+  <dl{{ attributes.addClass(classes) }}>
     {% for item in content %}
       <dt>{{ item.link }}</dt>
       {% if item.description %}
diff --git a/core/modules/system/templates/status-report.html.twig b/core/modules/system/templates/status-report.html.twig
index 7d0d96d7acd8..89f12d4172ef 100644
--- a/core/modules/system/templates/status-report.html.twig
+++ b/core/modules/system/templates/status-report.html.twig
@@ -10,7 +10,7 @@
  *   - value: (optional) The requirement's status.
  *   - description: (optional) The requirement's description.
  *   - severity_title: The title of the severity.
- *   - severity_class: The HTML class of the severity.
+ *   - severity_status: Indicates the severity status.
  *
  * @see template_preprocess_status_report()
  *
@@ -25,7 +25,7 @@
   </thead>
   <tbody>
   {% for requirement in requirements %}
-    <tr class="{{ requirement.severity_class }}">
+    <tr class="{{ requirement.severity_status }}">
       <td class="status-icon">
         <div title="{{ requirement.severity_title }}">
           <span class="visually-hidden">{{ requirement.severity_title }}</span>
diff --git a/core/modules/system/templates/system-themes-page.html.twig b/core/modules/system/templates/system-themes-page.html.twig
index 9d55c2171652..404fa1dea9c5 100644
--- a/core/modules/system/templates/system-themes-page.html.twig
+++ b/core/modules/system/templates/system-themes-page.html.twig
@@ -15,6 +15,10 @@
  *     - description: Description of the theme.
  *     - name: Theme name.
  *     - version: The theme's version number.
+ *     - is_default: Boolean indicating whether the theme is the default theme
+ *       or not.
+ *     - is_admin: Boolean indicating whether the theme is the admin theme or
+ *       not.
  *     - notes: Identifies what context this theme is being used in, e.g.,
  *       default theme, admin theme.
  *     - incompatible: Text describing any compatibility issues.
@@ -28,10 +32,25 @@
 #}
 <div{{ attributes }}>
   {% for theme_group in theme_groups %}
-    <div{{ theme_group.attributes }}>
+    {%
+      set theme_group_classes = [
+        'system-themes-list',
+        'system-themes-list-' ~ theme_group.state,
+        'clearfix',
+      ]
+    %}
+    <div{{ theme_group.attributes.addClass(theme_group_classes) }}>
       <h2>{{ theme_group.title }}</h2>
       {% for theme in theme_group.themes %}
-        <div{{ theme.attributes }}>
+        {%
+          set theme_classes = [
+            theme.is_default ? 'theme-default',
+            theme.is_admin ? 'theme-admin',
+            'theme-selector',
+            'clearfix',
+          ]
+        %}
+        <div{{ theme.attributes.addClass(theme_classes) }}>
           {% if theme.screenshot %}
             {{ theme.screenshot }}
           {% endif %}
diff --git a/core/themes/seven/templates/admin-block-content.html.twig b/core/themes/seven/templates/admin-block-content.html.twig
index 7dc0a92e484a..5991a1b5a6b2 100644
--- a/core/themes/seven/templates/admin-block-content.html.twig
+++ b/core/themes/seven/templates/admin-block-content.html.twig
@@ -11,13 +11,20 @@
  *   - title: Short name of the section.
  *   - description: Description of the administrative menu item.
  * - attributes: HTML attributes to be added to the element.
+ * - compact: Boolean indicating whether compact mode is turned on or not.
  *
  * @see template_preprocess_admin_block_content()
  * @see seven_preprocess_admin_block_content()
  */
 #}
+{%
+  set classes = [
+    'admin-list',
+    compact ? 'compact',
+  ]
+%}
 {% if content %}
-  <ul{{ attributes }}>
+  <ul{{ attributes.addClass(classes) }}>
     {% for item in content %}
       <li><a href="{{ item.url }}"><span class="label">{{ item.title }}</span><div class="description">{{ item.description }}</div></a></li>
     {% endfor %}
-- 
GitLab