Commit 6e8eb8ee authored by alexpott's avatar alexpott

Issue #2465887 by dawehner, amateescu, tim.plunkett: Extract the...

Issue #2465887 by dawehner, amateescu, tim.plunkett: Extract the install/uninstall functionality to a ThemeInstaller
parent 78cc7d8b
......@@ -434,7 +434,10 @@ services:
lazy: true
theme_handler:
class: Drupal\Core\Extension\ThemeHandler
arguments: ['@app.root', '@config.factory', '@module_handler', '@state', '@info_parser', '@logger.channel.default', '@asset.css.collection_optimizer', '@config.installer', '@config.manager', '@router.builder']
arguments: ['@app.root', '@config.factory', '@module_handler', '@state', '@info_parser']
theme_installer:
class: Drupal\Core\Extension\ThemeInstaller
arguments: ['@theme_handler', '@config.factory', '@config.installer', '@module_handler', '@config.manager', '@asset.css.collection_optimizer', '@router.builder', '@logger.channel.default', '@state']
entity.manager:
class: Drupal\Core\Entity\EntityManager
arguments: ['@container.namespaces', '@module_handler', '@cache.discovery', '@language_manager', '@string_translation', '@class_resolver', '@typed_data_manager', '@keyvalue', '@event_dispatcher']
......
......@@ -8,7 +8,7 @@
namespace Drupal\Core\Extension;
/**
* Manages the list of available themes as well as install/uninstall them.
* Manages the list of available themes.
*/
interface ThemeHandlerInterface {
......@@ -27,6 +27,11 @@ interface ThemeHandlerInterface {
*
* @throws \Drupal\Core\Extension\ExtensionNameLengthException
* Thrown when the theme name is to long
*
* @deprecated in Drupal 8.0.x-dev and will be removed before Drupal 9.0.0.
* Use the theme_installer service instead.
*
* @see \Drupal\Core\Extension\ThemeInstallerInterface::install
*/
public function install(array $theme_list, $install_dependencies = TRUE);
......@@ -43,6 +48,11 @@ public function install(array $theme_list, $install_dependencies = TRUE);
* Thrown when you uninstall an not installed theme.
*
* @see hook_themes_uninstalled()
*
* @deprecated in Drupal 8.0.x-dev and will be removed before Drupal 9.0.0.
* Use the theme_installer service instead.
*
* @see \Drupal\Core\Extension\ThemeInstallerInterface::install
*/
public function uninstall(array $theme_list);
......@@ -87,6 +97,15 @@ public function uninstall(array $theme_list);
*/
public function listInfo();
/**
* Adds a theme extension to the internal listing.
*
* @param \Drupal\Core\Extension\Extension $theme
* The theme extension.
*/
public function addTheme(Extension $theme);
/**
* Refreshes the theme info data of currently installed themes.
*
......
This diff is collapsed.
<?php
/**
* @file
* Contains \Drupal\Core\Extension\ThemeInstallerInterface.
*/
namespace Drupal\Core\Extension;
/**
* Manages theme installation/uninstallation.
*/
interface ThemeInstallerInterface {
/**
* Installs a given list of themes.
*
* @param array $theme_list
* An array of theme names.
* @param bool $install_dependencies
* (optional) If TRUE, dependencies will automatically be installed in the
* correct order. This incurs a significant performance cost, so use FALSE
* if you know $theme_list is already complete and in the correct order.
*
* @return bool
* Whether any of the given themes have been installed.
*
* @throws \Drupal\Core\Extension\ExtensionNameLengthException
* Thrown when the theme name is to long
*/
public function install(array $theme_list, $install_dependencies = TRUE);
/**
* Uninstalls a given list of themes.
*
* Uninstalling a theme removes all related configuration (like blocks) and
* invokes the 'themes_uninstalled' hook.
*
* @param array $theme_list
* The themes to uninstall.
*
* @throws \InvalidArgumentException
* Thrown when you uninstall an not installed theme.
*
* @see hook_themes_uninstalled()
*/
public function uninstall(array $theme_list);
}
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\system\Tests\Extension\ThemeHandlerTest.
* Contains \Drupal\system\Tests\Extension\ThemeInstallerTest.
*/
namespace Drupal\system\Tests\Extension;
......@@ -16,7 +16,7 @@
*
* @group Extension
*/
class ThemeHandlerTest extends KernelTestBase {
class ThemeInstallerTest extends KernelTestBase {
/**
* Modules to enable.
......@@ -63,7 +63,7 @@ function testInstall() {
$themes = $this->themeHandler()->listInfo();
$this->assertFalse(isset($themes[$name]));
$this->themeHandler()->install(array($name));
$this->themeInstaller()->install(array($name));
$this->assertIdentical($this->extensionConfig()->get("theme.$name"), 0);
......@@ -89,13 +89,13 @@ function testInstallSubTheme() {
$themes = $this->themeHandler()->listInfo();
$this->assertFalse(array_keys($themes));
$this->themeHandler()->install(array($name));
$this->themeInstaller()->install(array($name));
$themes = $this->themeHandler()->listInfo();
$this->assertTrue(isset($themes[$name]));
$this->assertTrue(isset($themes[$base_name]));
$this->themeHandler()->uninstall(array($name));
$this->themeInstaller()->uninstall(array($name));
$themes = $this->themeHandler()->listInfo();
$this->assertFalse(isset($themes[$name]));
......@@ -113,7 +113,7 @@ function testInstallNonExisting() {
try {
$message = 'ThemeHandler::install() throws InvalidArgumentException upon installing a non-existing theme.';
$this->themeHandler()->install(array($name));
$this->themeInstaller()->install(array($name));
$this->fail($message);
}
catch (\InvalidArgumentException $e) {
......@@ -132,7 +132,7 @@ function testInstallNameTooLong() {
try {
$message = 'ThemeHandler::install() throws ExtensionNameLengthException upon installing a theme with a too long name.';
$this->themeHandler()->install(array($name));
$this->themeInstaller()->install(array($name));
$this->fail($message);
}
catch (ExtensionNameLengthException $e) {
......@@ -146,7 +146,7 @@ function testInstallNameTooLong() {
function testUninstallDefault() {
$name = 'stark';
$other_name = 'bartik';
$this->themeHandler()->install(array($name, $other_name));
$this->themeInstaller()->install(array($name, $other_name));
$this->themeHandler()->setDefault($name);
$themes = $this->themeHandler()->listInfo();
......@@ -173,7 +173,7 @@ function testUninstallDefault() {
function testUninstallAdmin() {
$name = 'stark';
$other_name = 'bartik';
$this->themeHandler()->install(array($name, $other_name));
$this->themeInstaller()->install(array($name, $other_name));
$this->config('system.theme')->set('admin', $name)->save();
$themes = $this->themeHandler()->listInfo();
......@@ -201,8 +201,8 @@ function testUninstallSubTheme() {
$name = 'test_subtheme';
$base_name = 'test_basetheme';
$this->themeHandler()->install(array($name));
$this->themeHandler()->uninstall(array($name));
$this->themeInstaller()->install(array($name));
$this->themeInstaller()->uninstall(array($name));
$themes = $this->themeHandler()->listInfo();
$this->assertFalse(isset($themes[$name]));
......@@ -216,11 +216,11 @@ function testUninstallBaseBeforeSubTheme() {
$name = 'test_basetheme';
$sub_name = 'test_subtheme';
$this->themeHandler()->install(array($sub_name));
$this->themeInstaller()->install(array($sub_name));
try {
$message = 'ThemeHandler::install() throws InvalidArgumentException upon uninstalling base theme before sub theme.';
$this->themeHandler()->uninstall(array($name));
$this->themeInstaller()->uninstall(array($name));
$this->fail($message);
}
catch (\InvalidArgumentException $e) {
......@@ -232,7 +232,7 @@ function testUninstallBaseBeforeSubTheme() {
$this->assertTrue(isset($themes[$sub_name]));
// Verify that uninstalling both at the same time works.
$this->themeHandler()->uninstall(array($name, $sub_name));
$this->themeInstaller()->uninstall(array($name, $sub_name));
$themes = $this->themeHandler()->listInfo();
$this->assertFalse(isset($themes[$name]));
......@@ -250,7 +250,7 @@ function testUninstallNonExisting() {
try {
$message = 'ThemeHandler::uninstall() throws InvalidArgumentException upon uninstalling a non-existing theme.';
$this->themeHandler()->uninstall(array($name));
$this->themeInstaller()->uninstall(array($name));
$this->fail($message);
}
catch (\InvalidArgumentException $e) {
......@@ -267,10 +267,10 @@ function testUninstallNonExisting() {
function testUninstall() {
$name = 'test_basetheme';
$this->themeHandler()->install(array($name));
$this->themeInstaller()->install(array($name));
$this->assertTrue($this->config("$name.settings")->get());
$this->themeHandler()->uninstall(array($name));
$this->themeInstaller()->uninstall(array($name));
$this->assertFalse(array_keys($this->themeHandler()->listInfo()));
$this->assertFalse(array_keys(system_list('theme')));
......@@ -278,7 +278,7 @@ function testUninstall() {
$this->assertFalse($this->config("$name.settings")->get());
// Ensure that the uninstalled theme can be installed again.
$this->themeHandler()->install(array($name));
$this->themeInstaller()->install(array($name));
$themes = $this->themeHandler()->listInfo();
$this->assertTrue(isset($themes[$name]));
$this->assertEqual($themes[$name]->getName(), $name);
......@@ -294,7 +294,7 @@ function testUninstallNotInstalled() {
try {
$message = 'ThemeHandler::uninstall() throws InvalidArgumentException upon uninstalling a theme that is not installed.';
$this->themeHandler()->uninstall(array($name));
$this->themeInstaller()->uninstall(array($name));
$this->fail($message);
}
catch (\InvalidArgumentException $e) {
......@@ -311,7 +311,7 @@ function testThemeInfoAlter() {
$name = 'seven';
$this->container->get('state')->set('module_test.hook_system_info_alter', TRUE);
$this->themeHandler()->install(array($name));
$this->themeInstaller()->install(array($name));
$themes = $this->themeHandler()->listInfo();
$this->assertFalse(isset($themes[$name]->info['regions']['test_region']));
......@@ -362,21 +362,21 @@ protected function themeHandler() {
}
/**
* Returns the system.theme config object.
* Returns the theme installer service.
*
* @return \Drupal\Core\Config\Config
* @return \Drupal\Core\Extension\ThemeInstallerInterface
*/
protected function extensionConfig() {
return $this->config('core.extension');
protected function themeInstaller() {
return $this->container->get('theme_installer');
}
/**
* Returns the active configuration storage.
* Returns the system.theme config object.
*
* @return \Drupal\Core\Config\ConfigStorageInterface
* @return \Drupal\Core\Config\Config
*/
protected function configStorage() {
return $this->container->get('config.storage');
protected function extensionConfig() {
return $this->config('core.extension');
}
/**
......
# Themes are not supposed to provide/install this kind of config normally.
# This exists for testing purposes only.
# @see \Drupal\system\Tests\Extension\ThemeHandlerTest
# @see \Drupal\system\Tests\Extension\ThemeInstallerTest
id: fancy
label: 'Fancy date'
status: true
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Tests\Core\Extension\ThemeHandlerTest.
* Contains \Drupal\Tests\Core\Extension\ThemeInstallerTest.
*/
namespace Drupal\Tests\Core\Extension;
......@@ -10,7 +10,6 @@
use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\InfoParser;
use Drupal\Core\Extension\ThemeHandler;
use Drupal\Core\Config\ConfigInstaller;
use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
use Drupal\Core\State\State;
use Drupal\Tests\UnitTestCase;
......@@ -21,13 +20,6 @@
*/
class ThemeHandlerTest extends UnitTestCase {
/**
* The mocked route builder.
*
* @var \Drupal\Core\Routing\RouteBuilderInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $routeBuilder;
/**
* The mocked info parser.
*
......@@ -56,20 +48,6 @@ class ThemeHandlerTest extends UnitTestCase {
*/
protected $moduleHandler;
/**
* The mocked config installer.
*
* @var \Drupal\Core\Config\ConfigInstaller|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configInstaller;
/**
* The mocked config manager.
*
* @var \Drupal\Core\Config\ConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configManager;
/**
* The extension discovery.
*
......@@ -77,13 +55,6 @@ class ThemeHandlerTest extends UnitTestCase {
*/
protected $extensionDiscovery;
/**
* The CSS asset collection optimizer service.
*
* @var \Drupal\Core\Asset\AssetCollectionOptimizerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $cssCollectionOptimizer;
/**
* The tested theme handler.
*
......@@ -109,17 +80,10 @@ protected function setUp() {
$this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
$this->state = new State(new KeyValueMemoryFactory());
$this->infoParser = $this->getMock('Drupal\Core\Extension\InfoParserInterface');
$this->configInstaller = $this->getMock('Drupal\Core\Config\ConfigInstallerInterface');
$this->configManager = $this->getMock('Drupal\Core\Config\ConfigManagerInterface');
$this->routeBuilder = $this->getMock('Drupal\Core\Routing\RouteBuilderInterface');
$this->extensionDiscovery = $this->getMockBuilder('Drupal\Core\Extension\ExtensionDiscovery')
->disableOriginalConstructor()
->getMock();
$this->cssCollectionOptimizer = $this->getMockBuilder('\Drupal\Core\Asset\CssCollectionOptimizer')
->disableOriginalConstructor()
->getMock();
$logger = $this->getMock('Psr\Log\LoggerInterface');
$this->themeHandler = new StubThemeHandler($this->root, $this->configFactory, $this->moduleHandler, $this->state, $this->infoParser, $logger, $this->cssCollectionOptimizer, $this->configInstaller, $this->configManager, $this->routeBuilder, $this->extensionDiscovery);
$this->themeHandler = new StubThemeHandler($this->root, $this->configFactory, $this->moduleHandler, $this->state, $this->infoParser, $this->extensionDiscovery);
$cache_tags_invalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
$this->getContainerWithCacheTagsInvalidator($cache_tags_invalidator);
......
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