Commit b75c57ff authored by catch's avatar catch

Issue #2575421 by Cottser, mdrummond, lauriii, davidhernandez, LewisNyman,...

Issue #2575421 by Cottser, mdrummond, lauriii, davidhernandez, LewisNyman, catch, alexpott, joelpittet, webchick, Bojhan, emma.maria, mortendk: Add a Stable base theme to core and make it the default if a base theme is not specified
parent 17debf40
......@@ -252,6 +252,7 @@ public function rebuildThemeData() {
// Set defaults for theme info.
$defaults = array(
'engine' => 'twig',
'base theme' => 'stable',
'regions' => array(
'sidebar_first' => 'Left sidebar',
'sidebar_second' => 'Right sidebar',
......@@ -282,6 +283,11 @@ public function rebuildThemeData() {
$theme->status = (int) isset($installed[$key]);
$theme->info = $this->infoParser->parse($theme->getPathname()) + $defaults;
// Remove the default Stable base theme when 'base theme: false' is set in
// a theme .info.yml file.
if ($theme->info['base theme'] === FALSE) {
unset($theme->info['base theme']);
}
// Add the info file modification time, so it becomes available for
// contributed modules to use for ordering theme lists.
......
<?php
/**
* @file
* Contains \Drupal\system\Tests\Theme\StableThemeTest.
*/
namespace Drupal\system\Tests\Theme;
use Drupal\simpletest\KernelTestBase;
/**
* Tests the behavior of the Stable theme.
*
* @group Theme
*/
class StableThemeTest extends KernelTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = ['system'];
/**
* The theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* The theme manager.
*
* @var \Drupal\Core\Theme\ThemeManagerInterface
*/
protected $themeManager;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->themeHandler = $this->container->get('theme_handler');
$this->themeManager = $this->container->get('theme.manager');
}
/**
* Ensures Stable is used by default when no base theme has been defined.
*/
public function testStableIsDefault() {
$this->themeHandler->install(['test_stable']);
$this->config('system.theme')->set('default', 'test_stable')->save();
$theme = $this->themeManager->getActiveTheme();
/** @var \Drupal\Core\Theme\ActiveTheme $base_theme */
$base_themes = $theme->getBaseThemes();
$base_theme = reset($base_themes);
$this->assertTrue($base_theme->getName() == 'stable', "Stable theme is the base theme if a theme hasn't decided to opt out.");
}
/**
* Tests opting out of Stable by setting the base theme to false.
*/
public function testWildWest() {
$this->themeHandler->install(['test_wild_west']);
$this->config('system.theme')->set('default', 'test_wild_west')->save();
$theme = $this->themeManager->getActiveTheme();
/** @var \Drupal\Core\Theme\ActiveTheme $base_theme */
$base_themes = $theme->getBaseThemes();
$this->assertTrue(empty($base_themes), 'No base theme is set when a theme has opted out of using Stable.');
}
}
<?php
/**
* @file
* Contains \Drupal\system\Tests\Update\StableBaseThemeUpdateTest.
*/
namespace Drupal\system\Tests\Update;
/**
* Tests the upgrade path for introducing the Stable base theme.
*
* @see https://www.drupal.org/node/2575421
*
* @group system
*/
class StableBaseThemeUpdateTest extends UpdatePathTestBase {
/**
* The theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.stable-base-theme-2575421.php',
];
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->themeHandler = $this->container->get('theme_handler');
$this->themeHandler->refreshInfo();
}
/**
* Tests that the Stable base theme is installed if necessary.
*/
public function testUpdateHookN() {
$this->assertTrue($this->themeHandler->themeExists('test_stable'));
$this->assertFalse($this->themeHandler->themeExists('stable'));
$this->runUpdates();
// Refresh the theme handler now that Stable has been installed.
$this->themeHandler->refreshInfo();
$this->assertTrue($this->themeHandler->themeExists('stable'));
}
}
......@@ -1807,6 +1807,23 @@ function system_update_8011() {
_system_update_create_block($name, $theme_name, $values);
}
/**
* Install the Stable base theme if needed.
*/
function system_update_8012() {
$theme_handler = \Drupal::service('theme_handler');
// Ensure we have fresh info.
$theme_handler->rebuildThemeData();
foreach ($theme_handler->listInfo() as $theme) {
// We first check that a base theme is set because if it's set to false then
// it's unset in \Drupal\Core\Extension\ThemeHandler::rebuildThemeData().
if (isset($theme->info['base theme']) && $theme->info['base theme'] == 'stable') {
$theme_handler->install(['stable']);
return;
}
}
}
/**
* @} End of "addtogroup updates-8.0.0-beta".
*/
<?php
/**
* @file
* Contains database additions to drupal-8.bare.standard.php.gz for testing the
* upgrade path of https://www.drupal.org/node/2575421.
*/
use Drupal\Core\Database\Database;
$connection = Database::getConnection();
// Enable test_stable theme.
$extensions = $connection->select('config')
->fields('config', ['data'])
->condition('name', 'core.extension')
->execute()
->fetchField();
$extensions = unserialize($extensions);
$connection->update('config')
->fields([
'data' => serialize(array_merge_recursive($extensions, ['theme' => ['test_stable' => 0]]))
])
->condition('name', 'core.extension')
->execute();
......@@ -3,6 +3,7 @@ type: theme
description: 'Test theme which acts as a base theme for other test subthemes.'
version: VERSION
core: 8.x
base theme: false
libraries:
- test_basetheme/global-styling
stylesheets-remove:
......
......@@ -4,3 +4,4 @@ description: 'Test theme which has a non-existent theme engine.'
version: VERSION
core: 8.x
engine: not_real_engine
base theme: false
name: Test Stable
type: theme
description: A theme to test that stable is set as the default.
version: VERSION
core: 8.x
......@@ -4,3 +4,4 @@ description: 'Theme for testing the theme system with the Nyan Cat theme engine'
version: VERSION
core: 8.x
engine: nyan_cat
base theme: false
name: Test Wild West
type: theme
description: A theme that doesn't use Stable as its base. It tests the wild west instead.
version: VERSION
base theme: false
core: 8.x
......@@ -4,6 +4,7 @@ description: 'A base theme with sensible default CSS classes added. Learn how to
package: Core
version: VERSION
core: 8.x
base theme: false
libraries:
- classy/base
......
name: Stable
type: theme
description: A default base theme using Drupal 8.0.0's core markup, CSS, and JavaScript.
package: Core
version: VERSION
core: 8.x
base theme: false
......@@ -4,3 +4,4 @@ description: 'An intentionally plain theme with no styling to demonstrate defaul
package: Core
version: VERSION
core: 8.x
base theme: false
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment