From f1e618ec2578f7a26cfdf5c3131c278da3c0166c Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Mon, 27 Jul 2015 12:35:14 +0100
Subject: [PATCH] Issue #2489830 by cilefen, davidhernandez, dcmul, Adam
 Clarey, joshi.rohit100, rpayanm, sqndr, Cottser, lauriii: Improve theme
 compatibility error message

---
 core/modules/system/src/Controller/SystemController.php   | 3 ++-
 core/modules/system/src/Tests/System/ThemeTest.php        | 4 ++++
 core/modules/system/system.admin.inc                      | 5 ++++-
 .../themes/test_invalid_core/test_invalid_core.info.yml   | 5 +++++
 .../test_invalid_region/test_invalid_region.info.yml      | 8 ++++++++
 5 files changed, 23 insertions(+), 2 deletions(-)
 create mode 100644 core/modules/system/tests/themes/test_invalid_core/test_invalid_core.info.yml
 create mode 100644 core/modules/system/tests/themes/test_invalid_region/test_invalid_region.info.yml

diff --git a/core/modules/system/src/Controller/SystemController.php b/core/modules/system/src/Controller/SystemController.php
index 20ea39e409df..6bae39764d7f 100644
--- a/core/modules/system/src/Controller/SystemController.php
+++ b/core/modules/system/src/Controller/SystemController.php
@@ -241,9 +241,10 @@ public function themesPage() {
 
       if (empty($theme->status)) {
         // Ensure this theme is compatible with this version of core.
+        $theme->incompatible_core = !isset($theme->info['core']) || ($theme->info['core'] != \DRUPAL::CORE_COMPATIBILITY);
         // Require the 'content' region to make sure the main page
         // content has a common place in all themes.
-        $theme->incompatible_core = !isset($theme->info['core']) || ($theme->info['core'] != \DRUPAL::CORE_COMPATIBILITY) || !isset($theme->info['regions']['content']);
+        $theme->incompatible_region = !isset($theme->info['regions']['content']);
         $theme->incompatible_php = version_compare(phpversion(), $theme->info['php']) < 0;
         // Confirmed that the base theme is available.
         $theme->incompatible_base = isset($theme->info['base theme']) && !isset($themes[$theme->info['base theme']]);
diff --git a/core/modules/system/src/Tests/System/ThemeTest.php b/core/modules/system/src/Tests/System/ThemeTest.php
index 84745b7c2977..7c852758839f 100644
--- a/core/modules/system/src/Tests/System/ThemeTest.php
+++ b/core/modules/system/src/Tests/System/ThemeTest.php
@@ -273,6 +273,10 @@ function testInvalidTheme() {
     $this->drupalGet('admin/appearance');
     $this->assertText(t('This theme requires the base theme @base_theme to operate correctly.', array('@base_theme' => 'not_real_test_basetheme')));
     $this->assertText(t('This theme requires the theme engine @theme_engine to operate correctly.', array('@theme_engine' => 'not_real_engine')));
+    // Check for the error text of a theme with the wrong core version.
+    $this->assertText("This theme is not compatible with Drupal 8.x. Check that the .info.yml file contains the correct 'core' value.");
+    // Check for the error text of a theme without a content region.
+    $this->assertText("This theme is missing a 'content' region.");
   }
 
   /**
diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc
index 1141a353d71f..cc9184981bee 100644
--- a/core/modules/system/system.admin.inc
+++ b/core/modules/system/system.admin.inc
@@ -420,7 +420,10 @@ function template_preprocess_system_themes_page(&$variables) {
       // Make sure to provide feedback on compatibility.
       $current_theme['incompatible'] = '';
       if (!empty($theme->incompatible_core)) {
-        $current_theme['incompatible'] = t('This version is not compatible with Drupal !core_version and should be replaced.', array('!core_version' => \Drupal::CORE_COMPATIBILITY));
+        $current_theme['incompatible'] = t("This theme is not compatible with Drupal @core_version. Check that the .info.yml file contains the correct 'core' value.", ['@core_version' => \Drupal::CORE_COMPATIBILITY]);
+      }
+      elseif (!empty($theme->incompatible_region)) {
+        $current_theme['incompatible'] = t("This theme is missing a 'content' region.");
       }
       elseif (!empty($theme->incompatible_php)) {
         if (substr_count($theme->info['php'], '.') < 2) {
diff --git a/core/modules/system/tests/themes/test_invalid_core/test_invalid_core.info.yml b/core/modules/system/tests/themes/test_invalid_core/test_invalid_core.info.yml
new file mode 100644
index 000000000000..5c369a64e690
--- /dev/null
+++ b/core/modules/system/tests/themes/test_invalid_core/test_invalid_core.info.yml
@@ -0,0 +1,5 @@
+name: 'Theme test with invalid core version'
+type: theme
+description: 'Test theme which has an invalid core version.'
+version: VERSION
+core: 7.x
diff --git a/core/modules/system/tests/themes/test_invalid_region/test_invalid_region.info.yml b/core/modules/system/tests/themes/test_invalid_region/test_invalid_region.info.yml
new file mode 100644
index 000000000000..6fef32a21dc3
--- /dev/null
+++ b/core/modules/system/tests/themes/test_invalid_region/test_invalid_region.info.yml
@@ -0,0 +1,8 @@
+name: 'Theme test with missing content region'
+type: theme
+description: 'Test theme which has a non-existent content region.'
+version: VERSION
+core: 8.x
+
+regions:
+  - foo: Foo
-- 
GitLab