Issue #2329795 by fietserwin, bzitzow, alexrayu, tstoeckler | illutek, dawehner: Fixed Make it possible to add information to theme info files during development.

8.0.x
Nathaniel Catchpole 2014-09-05 11:11:16 +01:00
parent 285df2c54d
commit 57fc261527
5 changed files with 90 additions and 10 deletions

View File

@ -3547,7 +3547,20 @@ function drupal_flush_all_caches() {
// Rebuild module and theme data.
$module_data = system_rebuild_module_data();
system_rebuild_theme_data();
/** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
$theme_handler = \Drupal::service('theme_handler');
$theme_handler->refreshInfo();
// Remove the cache of the active theme's info file information in state.
// @see \Drupal\Core\Theme\ThemeInitialization::getActiveByThemeName()
$keys = [];
foreach ($theme_handler->listInfo() as $theme_name => $theme) {
$keys[] = 'theme.active_theme.' . $theme_name;
}
\Drupal::state()->deleteMultiple($keys);
// In case the active theme gets requested later in the same request we need
// to reset the theme manager.
\Drupal::theme()->resetActiveTheme();
// Rebuild and reboot a new kernel. A simple DrupalKernel reboot is not
// sufficient, since the list of enabled modules might have been adjusted

View File

@ -407,7 +407,7 @@ class ThemeHandler implements ThemeHandlerInterface {
$list = $this->rebuildThemeData();
foreach ($list as $name => $theme) {
if (isset($enabled[$name])) {
$this->list[$name] = $theme;
$this->addTheme($theme);
}
}
$this->state->set('system.theme.data', $this->list);

View File

@ -18,9 +18,9 @@ class DefaultNegotiator implements ThemeNegotiatorInterface {
/**
* The system theme config object.
*
* @var \Drupal\Core\Config\Config
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $config;
protected $configFactory;
/**
* Constructs a DefaultNegotiator object.
@ -29,7 +29,7 @@ class DefaultNegotiator implements ThemeNegotiatorInterface {
* The config factory.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->config = $config_factory->get('system.theme');
$this->configFactory = $config_factory;
}
/**
@ -43,7 +43,7 @@ class DefaultNegotiator implements ThemeNegotiatorInterface {
* {@inheritdoc}
*/
public function determineActiveTheme(RouteMatchInterface $route_match) {
return $this->config->get('default');
return $this->configFactory->get('system.theme')->get('default');
}
}

View File

@ -2,7 +2,7 @@
/**
* @file
* Contains Drupal\system\Tests\Theme\ThemeInfoStylesTest.
* Contains Drupal\system\Tests\Theme\ThemeInfoTest.
*/
namespace Drupal\system\Tests\Theme;
@ -10,11 +10,11 @@ namespace Drupal\system\Tests\Theme;
use Drupal\simpletest\WebTestBase;
/**
* Tests processing of theme .info.yml stylesheets.
* Tests processing of theme .info.yml properties.
*
* @group Theme
*/
class ThemeInfoStylesTest extends WebTestBase {
class ThemeInfoTest extends WebTestBase {
/**
* Modules to enable.
@ -23,11 +23,43 @@ class ThemeInfoStylesTest extends WebTestBase {
*/
public static $modules = array('theme_test');
/**
* The theme handler used in this test for enabling themes.
*
* @var \Drupal\Core\Extension\ThemeHandler
*/
protected $themeHandler;
/**
* The theme manager used in this test.
*
* @var \Drupal\Core\Theme\ThemeManagerInterface
*/
protected $themeManager;
/**
* The state service used in this test.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->themeHandler = $this->container->get('theme_handler');
$this->themeManager = $this->container->get('theme.manager');
$this->state = $this->container->get('state');
}
/**
* Tests stylesheets-override and stylesheets-remove.
*/
function testStylesheets() {
theme_enable(array('test_basetheme', 'test_subtheme'));
$this->themeHandler->enable(array('test_basetheme', 'test_subtheme'));
\Drupal::config('system.theme')
->set('default', 'test_subtheme')
->save();
@ -56,4 +88,24 @@ class ThemeInfoStylesTest extends WebTestBase {
$this->assertIdentical(0, count($this->xpath("//link[contains(@href, 'base-override.sub-remove.css')]")), "base-override.sub-remove.css not found");
}
/**
* Tests that changes to the info file are picked up.
*/
public function testChanges() {
$this->themeHandler->enable(array('test_theme'));
$this->themeHandler->setDefault('test_theme');
$this->themeManager->resetActiveTheme();
$active_theme = $this->themeManager->getActiveTheme();
// Make sure we are not testing the wrong theme.
$this->assertEqual('test_theme', $active_theme->getName());
$this->assertEqual([], $active_theme->getLibraries());
// @see theme_test_system_info_alter()
$this->state->set('theme_test.modify_info_files', TRUE);
drupal_flush_all_caches();
$active_theme = $this->themeManager->getActiveTheme();
$this->assertEqual(['core/backbone'], $active_theme->getLibraries());
}
}

View File

@ -1,5 +1,7 @@
<?php
use Drupal\Core\Extension\Extension;
/**
* Implements hook_theme().
*/
@ -148,3 +150,16 @@ function theme_test_theme_suggestions_theme_test_suggestions_alter(array &$sugge
function theme_theme_test_suggestions_include($variables) {
return 'Original function before altering theme suggestions.';
}
/**
* Implements hook_system_info_alter().
*
* @see \Drupal\system\Tests\Theme\ThemeInfoTest::testChanges()
*/
function theme_test_system_info_alter(array &$info, Extension $file, $type) {
if ($type == 'theme' && $file->getName() == 'test_theme' && \Drupal::state()->get('theme_test.modify_info_files')) {
// Add a library to see if the system picks it up.
$info += ['libraries' => []];
$info['libraries'][] = 'core/backbone';
}
}