From e06c4610db756202550eda9dba3c16fd1f398df4 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Mon, 6 Aug 2012 14:18:08 +0100 Subject: [PATCH] Issue #304540 by Rob Loach, marcingy, typhonius, BrockBoland, jaredsmith: Fixed Disable themes when theme engine or base theme arn't available. --- .../Drupal/system/Tests/System/ThemeTest.php | 10 +++++++++ core/modules/system/system.admin.inc | 12 ++++++++++- .../theme_page_test/theme_page_test.info | 6 ++++++ .../theme_page_test/theme_page_test.module | 21 +++++++++++++++++++ .../test_invalid_basetheme.info | 5 +++++ .../test_invalid_engine.info | 5 +++++ 6 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 core/modules/system/tests/modules/theme_page_test/theme_page_test.info create mode 100644 core/modules/system/tests/modules/theme_page_test/theme_page_test.module create mode 100644 core/modules/system/tests/themes/test_invalid_basetheme/test_invalid_basetheme.info create mode 100644 core/modules/system/tests/themes/test_invalid_engine/test_invalid_engine.info diff --git a/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php index 30d84223d0b2..ed43e49aa841 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php @@ -231,4 +231,14 @@ function testSwitchDefaultTheme() { $this->drupalGet('admin/structure/block'); $this->assertText('Stark(' . t('active tab') . ')', t('Default local task on blocks admin page has changed.')); } + + /** + * Test that themes can't be enabled when the base theme or engine is missing. + */ + function testInvalidTheme() { + module_enable(array('theme_page_test')); + $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')), 'Invalid base theme check succeeded.'); + $this->assertText(t('This theme requires the theme engine @theme_engine to operate correctly.', array('@theme_engine' => 'not_real_engine')), 'Invalid theme engine check succeeded.'); + } } diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 2947245d4ea6..2e424adbee4f 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -156,10 +156,14 @@ function system_themes_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_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']])); + // Confirm that the theme engine is available. + $theme->incompatible_engine = (isset($theme->info['engine']) && !isset($theme->owner)); } $query['token'] = drupal_get_token('system-theme-operation-link'); $theme->operations = array(); - if (!empty($theme->status) || !$theme->incompatible_core && !$theme->incompatible_php) { + if (!empty($theme->status) || !$theme->incompatible_core && !$theme->incompatible_php && !$theme->incompatible_base && !$theme->incompatible_engine) { // Create the operations links. $query['theme'] = $theme->name; if (drupal_theme_access($theme)) { @@ -2725,6 +2729,12 @@ function theme_system_themes_page($variables) { } $output .= '<div class="incompatible">' . t('This theme requires PHP version @php_required and is incompatible with PHP version !php_version.', array('@php_required' => $theme->info['php'], '!php_version' => phpversion())) . '</div>'; } + elseif (!empty($theme->incompatible_base)) { + $output .= '<div class="incompatible">' . t('This theme requires the base theme @base_theme to operate correctly.', array('@base_theme' => $theme->info['base theme'])) . '</div>'; + } + elseif (!empty($theme->incompatible_engine)) { + $output .= '<div class="incompatible">' . t('This theme requires the theme engine @theme_engine to operate correctly.', array('@theme_engine' => $theme->info['engine'])) . '</div>'; + } else { $output .= theme('links', array('links' => $theme->operations, 'attributes' => array('class' => array('operations', 'clearfix')))); } diff --git a/core/modules/system/tests/modules/theme_page_test/theme_page_test.info b/core/modules/system/tests/modules/theme_page_test/theme_page_test.info new file mode 100644 index 000000000000..78e5bb42d586 --- /dev/null +++ b/core/modules/system/tests/modules/theme_page_test/theme_page_test.info @@ -0,0 +1,6 @@ +name = "Theme page test" +description = "Support module for theme system testing." +package = Testing +version = VERSION +core = 8.x + diff --git a/core/modules/system/tests/modules/theme_page_test/theme_page_test.module b/core/modules/system/tests/modules/theme_page_test/theme_page_test.module new file mode 100644 index 000000000000..fe86da9cd8b3 --- /dev/null +++ b/core/modules/system/tests/modules/theme_page_test/theme_page_test.module @@ -0,0 +1,21 @@ +<?php + +/** + * Implements hook_system_info_alter(). + */ +function theme_page_test_system_info_alter(&$info, $file, $type) { + // Make sure that all themes are visible on the Appearance form. + if ($type == 'theme') { + unset($info['hidden']); + } +} + + +/** + * Implements hook_system_theme_info(). + */ +function theme_page_test_system_theme_info() { + $themes['test_invalid_basetheme'] = drupal_get_path('module', 'system') . '/tests/themes/test_invalid_basetheme/test_invalid_basetheme.info'; + $themes['test_invalid_engine'] = drupal_get_path('module', 'system') . '/tests/themes/test_invalid_engine/test_invalid_engine.info'; + return $themes; +} \ No newline at end of file diff --git a/core/modules/system/tests/themes/test_invalid_basetheme/test_invalid_basetheme.info b/core/modules/system/tests/themes/test_invalid_basetheme/test_invalid_basetheme.info new file mode 100644 index 000000000000..915a5c7c38b7 --- /dev/null +++ b/core/modules/system/tests/themes/test_invalid_basetheme/test_invalid_basetheme.info @@ -0,0 +1,5 @@ +name = Theme test with invalid base theme +description = Test theme which has a non-existent base theme. +core = 8.x +base theme = not_real_test_basetheme +hidden = TRUE diff --git a/core/modules/system/tests/themes/test_invalid_engine/test_invalid_engine.info b/core/modules/system/tests/themes/test_invalid_engine/test_invalid_engine.info new file mode 100644 index 000000000000..335600d70052 --- /dev/null +++ b/core/modules/system/tests/themes/test_invalid_engine/test_invalid_engine.info @@ -0,0 +1,5 @@ +name = Theme test with invalid theme engine +description = Test theme which has a non-existent theme engine. +core = 8.x +hidden = TRUE +engine = not_real_engine \ No newline at end of file -- GitLab