diff --git a/core/config/install/core.extension.yml b/core/config/install/core.extension.yml index 1514a9e..ce74bae 100644 --- a/core/config/install/core.extension.yml +++ b/core/config/install/core.extension.yml @@ -1,4 +1,2 @@ module: {} theme: {} -disabled: - theme: {} diff --git a/core/config/schema/core.extension.schema.yml b/core/config/schema/core.extension.schema.yml index 3b93d92..1d09eeb 100644 --- a/core/config/schema/core.extension.schema.yml +++ b/core/config/schema/core.extension.schema.yml @@ -10,17 +10,7 @@ core.extension: label: 'Weight' theme: type: sequence - label: 'Enabled themes' + label: 'Installed themes' sequence: - type: integer label: 'Weight' - disabled: - type: mapping - label: 'Disabled extensions' - mapping: - theme: - type: sequence - label: 'Disabled themes' - sequence: - - type: integer - label: 'Weight' diff --git a/core/core.services.yml b/core/core.services.yml index b7c686a..b8d5de8 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -283,7 +283,7 @@ services: arguments: ['%container.modules%', '@cache.bootstrap'] theme_handler: class: Drupal\Core\Extension\ThemeHandler - arguments: ['@config.factory', '@module_handler', '@state', '@info_parser', '@logger.channel.default', '@asset.css.collection_optimizer', '@config.installer', '@router.builder'] + arguments: ['@config.factory', '@module_handler', '@state', '@info_parser', '@logger.channel.default', '@asset.css.collection_optimizer', '@config.installer', '@config.manager', '@router.builder'] entity.manager: class: Drupal\Core\Entity\EntityManager arguments: ['@container.namespaces', '@module_handler', '@cache.discovery', '@language_manager', '@string_translation', '@class_resolver', '@typed_data_manager', '@entity.definitions.installed'] diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index f1e0be1..3909697 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1512,7 +1512,7 @@ function install_profile_modules(&$install_state) { * Installs themes. * * This does not use a batch, since installing themes is faster than modules and - * because an installation profile typically enables 1-3 themes only (default + * because an installation profile typically installs 1-3 themes only (default * theme, base theme, admin theme). * * @param $install_state @@ -1521,15 +1521,15 @@ function install_profile_modules(&$install_state) { function install_profile_themes(&$install_state) { $theme_handler = \Drupal::service('theme_handler'); - // ThemeHandler::enable() resets the current list of themes. The theme used in - // the installer is not necessarily in the list of themes to install, so + // ThemeHandler::install() resets the current list of themes. The theme used + // in the installer is not necessarily in the list of themes to install, so // retain the current list. // @see _drupal_maintenance_theme() $current_themes = $theme_handler->listInfo(); // Install the themes specified by the installation profile. $themes = $install_state['profile_info']['themes']; - $theme_handler->enable($themes); + $theme_handler->install($themes); foreach ($current_themes as $theme) { $theme_handler->addTheme($theme); diff --git a/core/includes/module.inc b/core/includes/module.inc index 023c102..2b668cb 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -9,11 +9,11 @@ use Drupal\Core\Extension\ExtensionDiscovery; /** - * Builds a list of enabled themes. + * Builds a list of installed themes. * * @param $type * The type of list to return: - * - theme: All enabled themes. + * - theme: All installed themes. * * @return * An associative array of themes, keyed by name. diff --git a/core/includes/theme.inc b/core/includes/theme.inc index b349918..222940a 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -77,7 +77,7 @@ * Either the name of a theme or a full theme object. * * @return bool - * Boolean TRUE if the theme is enabled or is the site administration theme; + * Boolean TRUE if the theme is installed or is the site administration theme; * FALSE otherwise. * * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. @@ -766,42 +766,6 @@ function theme_settings_convert_to_config(array $theme_settings, Config $config) } /** - * Enables a given list of themes. - * - * @param $theme_list - * An array of theme names. - * - * @return bool - * Whether any of the given themes have been enabled. - * - * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. - * Use \Drupal::service('theme_handler')->enable(). - * - * @see \Drupal\Core\Extension\ThemeHandler::enable(). - */ -function theme_enable($theme_list) { - return \Drupal::service('theme_handler')->enable($theme_list); -} - -/** - * Disables a given list of themes. - * - * @param $theme_list - * An array of theme names. - * - * @return bool - * Whether any of the given themes have been disabled. - * - * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. - * Use \Drupal::service('theme_handler')->disable(). - * - * @see \Drupal\Core\Extension\ThemeHandler::disable(). - */ -function theme_disable($theme_list) { - return \Drupal::service('theme_handler')->disable($theme_list); -} - -/** * @addtogroup themeable * @{ */ diff --git a/core/includes/update.inc b/core/includes/update.inc index 125907d..478d1a9 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -23,9 +23,6 @@ function update_fix_compatibility() { foreach ($extension_config->get($type) as $name => $weight) { if (update_check_incompatibility($name, $type)) { $extension_config->clear("$type.$name"); - if ($type === 'theme') { - $extension_config->set("disabled.theme.$name", 0); - } $save = TRUE; } } diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index b87c76d..9992fa0 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -124,7 +124,7 @@ class ConfigImporter { protected $themeHandler; /** - * Flag set to import system.theme during processing theme enable and disables. + * Flag set to import system.theme during processing theme install and uninstalls. * * @var bool */ @@ -252,8 +252,8 @@ protected function getEmptyExtensionsProcessedList() { 'uninstall' => array(), ), 'theme' => array( - 'enable' => array(), - 'disable' => array(), + 'install' => array(), + 'uninstall' => array(), ), ); } @@ -395,9 +395,9 @@ protected function createExtensionChangelist() { $module_list = array_reverse($module_list); $install = array_intersect(array_keys($module_list), $install); - // Work out what themes to enable and to disable. - $enable = array_diff(array_keys($new_extensions['theme']), array_keys($current_extensions['theme'])); - $disable = array_diff(array_keys($current_extensions['theme']), array_keys($new_extensions['theme'])); + // Work out what themes to install and to uninstall. + $theme_install = array_diff(array_keys($new_extensions['theme']), array_keys($current_extensions['theme'])); + $theme_uninstall = array_diff(array_keys($current_extensions['theme']), array_keys($new_extensions['theme'])); $this->extensionChangelist = array( 'module' => array( @@ -405,8 +405,8 @@ protected function createExtensionChangelist() { 'install' => $install, ), 'theme' => array( - 'enable' => $enable, - 'disable' => $disable, + 'install' => $theme_install, + 'uninstall' => $theme_uninstall, ), ); } @@ -441,20 +441,10 @@ protected function getExtensionChangelist($type, $op = NULL) { */ protected function getUnprocessedExtensions($type) { $changelist = $this->getExtensionChangelist($type); - - if ($type == 'theme') { - $unprocessed = array( - 'enable' => array_diff($changelist['enable'], $this->processedExtensions[$type]['enable']), - 'disable' => array_diff($changelist['disable'], $this->processedExtensions[$type]['disable']), - ); - } - else { - $unprocessed = array( - 'install' => array_diff($changelist['install'], $this->processedExtensions[$type]['install']), - 'uninstall' => array_diff($changelist['uninstall'], $this->processedExtensions[$type]['uninstall']), - ); - } - return $unprocessed; + return array( + 'install' => array_diff($changelist['install'], $this->processedExtensions[$type]['install']), + 'uninstall' => array_diff($changelist['uninstall'], $this->processedExtensions[$type]['uninstall']), + ); } /** @@ -533,7 +523,7 @@ public function initialize() { $this->totalExtensionsToProcess += count($modules[$op]); } $themes = $this->getUnprocessedExtensions('theme'); - foreach (array('enable', 'disable') as $op) { + foreach (array('install', 'uninstall') as $op) { $this->totalExtensionsToProcess += count($themes[$op]); } @@ -576,7 +566,7 @@ protected function processExtensions(array &$context) { $this->processExtension($operation['type'], $operation['op'], $operation['name']); $context['message'] = t('Synchronising extensions: @op @name.', array('@op' => $operation['op'], '@name' => $operation['name'])); $processed_count = count($this->processedExtensions['module']['install']) + count($this->processedExtensions['module']['uninstall']); - $processed_count += count($this->processedExtensions['theme']['disable']) + count($this->processedExtensions['theme']['enable']); + $processed_count += count($this->processedExtensions['theme']['uninstall']) + count($this->processedExtensions['theme']['install']); $context['finished'] = $processed_count / $this->totalExtensionsToProcess; } else { @@ -650,24 +640,16 @@ protected function finish(array &$context) { * on. If there is nothing left to do returns FALSE; */ protected function getNextExtensionOperation() { - foreach (array('install', 'uninstall') as $op) { - $modules = $this->getUnprocessedExtensions('module'); - if (!empty($modules[$op])) { - return array( - 'op' => $op, - 'type' => 'module', - 'name' => array_shift($modules[$op]), - ); - } - } - foreach (array('enable', 'disable') as $op) { - $themes = $this->getUnprocessedExtensions('theme'); - if (!empty($themes[$op])) { - return array( - 'op' => $op, - 'type' => 'theme', - 'name' => array_shift($themes[$op]), - ); + foreach (array('module', 'theme') as $type) { + foreach (array('install', 'uninstall') as $op) { + $unprocessed = $this->getUnprocessedExtensions($type); + if (!empty($unprocessed[$op])) { + return array( + 'op' => $op, + 'type' => $type, + 'name' => array_shift($unprocessed[$op]), + ); + } } } return FALSE; @@ -794,11 +776,11 @@ protected function processExtension($type, $op, $name) { $this->moduleHandler->loadAll(); } if ($type == 'theme') { - // Theme disables possible remove default or admin themes therefore we - // need to import this before doing any. If there are no disables and - // the default or admin theme is change this will be picked up whilst + // Theme uninstalls possible remove default or admin themes therefore we + // need to import this before doing any. If there are no uninstalls and + // the default or admin theme is changing this will be picked up whilst // processing configuration. - if ($op == 'disable' && $this->processedSystemTheme === FALSE) { + if ($op == 'uninstall' && $this->processedSystemTheme === FALSE) { $this->importConfig(StorageInterface::DEFAULT_COLLECTION, 'update', 'system.theme'); $this->configManager->getConfigFactory()->reset('system.theme'); $this->processedSystemTheme = TRUE; diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php index a4a086a..f42f1bd 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -12,12 +12,13 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigInstallerInterface; +use Drupal\Core\Config\ConfigManagerInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\Routing\RouteBuilder; use Psr\Log\LoggerInterface; /** - * Default theme handler using the config system for enabled/disabled themes. + * Default theme handler using the config system to store installation statuses. */ class ThemeHandler implements ThemeHandlerInterface { @@ -46,14 +47,14 @@ class ThemeHandler implements ThemeHandlerInterface { protected $list; /** - * The config factory to get the enabled themes. + * The config factory to get the installed themes. * * @var \Drupal\Core\Config\ConfigFactoryInterface */ protected $configFactory; /** - * The module handler to fire themes_enabled/themes_disabled hooks. + * The module handler to fire themes_installed/themes_uninstalled hooks. * * @var \Drupal\Core\Extension\ModuleHandlerInterface */ @@ -88,7 +89,7 @@ class ThemeHandler implements ThemeHandlerInterface { protected $logger; /** - * The route builder to rebuild the routes if a theme is enabled. + * The route builder to rebuild the routes if a theme is installed. * * @var \Drupal\Core\Routing\RouteBuilder */ @@ -109,30 +110,40 @@ class ThemeHandler implements ThemeHandlerInterface { protected $cssCollectionOptimizer; /** + * The config manager used to uninstall a theme. + * + * @var \Drupal\Core\Config\ConfigManagerInterface + */ + protected $configManager; + + /** * Constructs a new ThemeHandler. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory to get the enabled themes. + * The config factory to get the installed themes. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler to fire themes_enabled/themes_disabled hooks. + * The module handler to fire themes_installed/themes_uninstalled hooks. * @param \Drupal\Core\State\StateInterface $state * The state store. * @param \Drupal\Core\Extension\InfoParserInterface $info_parser * The info parser to parse the theme.info.yml files. - * @param \Drupal\Core\Asset\AssetCollectionOptimizerInterface $css_collection_optimizer - * The CSS asset collection optimizer service. * @param \Psr\Log\LoggerInterface $logger * A logger instance. + * @param \Drupal\Core\Asset\AssetCollectionOptimizerInterface $css_collection_optimizer + * The CSS asset collection optimizer service. * @param \Drupal\Core\Config\ConfigInstallerInterface $config_installer * (optional) The config installer to install configuration. This optional * to allow the theme handler to work before Drupal is installed and has a * database. + * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager + * The config manager used to uninstall a theme. * @param \Drupal\Core\Routing\RouteBuilder $route_builder - * (optional) The route builder to rebuild the routes if a theme is enabled. + * (optional) The route builder to rebuild the routes if a theme is + * installed. * @param \Drupal\Core\Extension\ExtensionDiscovery $extension_discovery * (optional) A extension discovery instance (for unit tests). */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state, InfoParserInterface $info_parser,LoggerInterface $logger, AssetCollectionOptimizerInterface $css_collection_optimizer = NULL, ConfigInstallerInterface $config_installer = NULL, RouteBuilder $route_builder = NULL, ExtensionDiscovery $extension_discovery = NULL) { + public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state, InfoParserInterface $info_parser,LoggerInterface $logger, AssetCollectionOptimizerInterface $css_collection_optimizer = NULL, ConfigInstallerInterface $config_installer = NULL, ConfigManagerInterface $config_manager = NULL, RouteBuilder $route_builder = NULL, ExtensionDiscovery $extension_discovery = NULL) { $this->configFactory = $config_factory; $this->moduleHandler = $module_handler; $this->state = $state; @@ -140,6 +151,7 @@ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandle $this->logger = $logger; $this->cssCollectionOptimizer = $css_collection_optimizer; $this->configInstaller = $config_installer; + $this->configManager = $config_manager; $this->routeBuilder = $route_builder; $this->extensionDiscovery = $extension_discovery; } @@ -157,7 +169,7 @@ public function getDefault() { public function setDefault($name) { $list = $this->listInfo(); if (!isset($list[$name])) { - throw new \InvalidArgumentException("$name theme is not enabled."); + throw new \InvalidArgumentException("$name theme is not installed."); } $this->configFactory->get('system.theme') ->set('default', $name) @@ -168,12 +180,12 @@ public function setDefault($name) { /** * {@inheritdoc} */ - public function enable(array $theme_list, $enable_dependencies = TRUE) { + public function install(array $theme_list, $install_dependencies = TRUE) { $extension_config = $this->configFactory->get('core.extension'); $theme_data = $this->rebuildThemeData(); - if ($enable_dependencies) { + if ($install_dependencies) { $theme_list = array_combine($theme_list, $theme_list); if ($missing = array_diff_key($theme_list, $theme_data)) { @@ -183,13 +195,12 @@ public function enable(array $theme_list, $enable_dependencies = TRUE) { ))); } - // Only process themes that are not enabled currently. + // Only process themes that are not installed currently. $installed_themes = $extension_config->get('theme') ?: array(); if (!$theme_list = array_diff_key($theme_list, $installed_themes)) { - // Nothing to do. All themes already enabled. + // Nothing to do. All themes already installed. return TRUE; } - $installed_themes += $extension_config->get('disabled.theme') ?: array(); while (list($theme) = each($theme_list)) { // Add dependencies to the list. The new themes will be processed as @@ -218,14 +229,13 @@ public function enable(array $theme_list, $enable_dependencies = TRUE) { } else { $installed_themes = $extension_config->get('theme') ?: array(); - $installed_themes += $extension_config->get('disabled.theme') ?: array(); } - $themes_enabled = array(); + $themes_installed = array(); foreach ($theme_list as $key) { - // Only process themes that are not already enabled. - $enabled = $extension_config->get("theme.$key") !== NULL; - if ($enabled) { + // Only process themes that are not already installed. + $installed = $extension_config->get("theme.$key") !== NULL; + if ($installed) { continue; } @@ -240,7 +250,6 @@ public function enable(array $theme_list, $enable_dependencies = TRUE) { // The value is not used; the weight is ignored for themes currently. $extension_config ->set("theme.$key", 0) - ->clear("disabled.theme.$key") ->save(); // Add the theme to the current list. @@ -263,11 +272,12 @@ public function enable(array $theme_list, $enable_dependencies = TRUE) { // Only install default configuration if this theme has not been installed // already. if (!isset($installed_themes[$key])) { - // The default config installation storage only knows about the currently - // enabled list of themes, so it has to be reset in order to pick up the - // default config of the newly installed theme. However, do not reset the - // source storage when synchronizing configuration, since that would - // needlessly trigger a reload of the whole configuration to be imported. + // The default config installation storage only knows about the + // currently installed list of themes, so it has to be reset in order to + // pick up the default config of the newly installed theme. However, do + // not reset the source storage when synchronizing configuration, since + // that would needlessly trigger a reload of the whole configuration to + // be imported. if (!$this->configInstaller->isSyncing()) { $this->configInstaller->resetSourceStorage(); } @@ -276,58 +286,57 @@ public function enable(array $theme_list, $enable_dependencies = TRUE) { $this->configInstaller->installDefaultConfig('theme', $key); } - $themes_enabled[] = $key; + $themes_installed[] = $key; - // Record the fact that it was enabled. - $this->logger->info('%theme theme enabled.', array('%theme' => $key)); + // Record the fact that it was installed. + $this->logger->info('%theme theme installed.', array('%theme' => $key)); } $this->cssCollectionOptimizer->deleteAll(); $this->resetSystem(); - // Invoke hook_themes_enabled() after the themes have been enabled. - $this->moduleHandler->invokeAll('themes_enabled', array($themes_enabled)); + // Invoke hook_themes_installed() after the themes have been installed. + $this->moduleHandler->invokeAll('themes_installed', array($themes_installed)); - return !empty($themes_enabled); + return !empty($themes_installed); } /** * {@inheritdoc} */ - public function disable(array $theme_list) { - $list = $this->listInfo(); + public function uninstall(array $theme_list) { + $extension_config = $this->configFactory->get('core.extension'); $theme_config = $this->configFactory->get('system.theme'); - + $list = $this->listInfo(); foreach ($theme_list as $key) { if (!isset($list[$key])) { throw new \InvalidArgumentException("Unknown theme: $key."); } if ($key === $theme_config->get('default')) { - throw new \InvalidArgumentException("The current default theme $key cannot be disabled."); + throw new \InvalidArgumentException("The current default theme $key cannot be uninstalled."); } if ($key === $theme_config->get('admin')) { - throw new \InvalidArgumentException("The current admin theme $key cannot be disabled."); + throw new \InvalidArgumentException("The current admin theme $key cannot be uninstalled."); } - // Base themes cannot be disabled if sub themes are enabled, and if they - // are not disabled at the same time. + // Base themes cannot be uninstalled if sub themes are installed, and if + // they are not uninstalled at the same time. + // @todo https://www.drupal.org/node/474684 and + // https://www.drupal.org/node/1297856 themes should leverage the module + // dependency system. if (!empty($list[$key]->sub_themes)) { foreach ($list[$key]->sub_themes as $sub_key => $sub_label) { if (isset($list[$sub_key]) && !in_array($sub_key, $theme_list, TRUE)) { - throw new \InvalidArgumentException("The base theme $key cannot be disabled, because theme $sub_key depends on it."); + throw new \InvalidArgumentException("The base theme $key cannot be uninstalled, because theme $sub_key depends on it."); } } } } $this->cssCollectionOptimizer->deleteAll(); - - $extension_config = $this->configFactory->get('core.extension'); $current_theme_data = $this->state->get('system.theme.data', array()); foreach ($theme_list as $key) { // The value is not used; the weight is ignored for themes currently. - $extension_config - ->clear("theme.$key") - ->set("disabled.theme.$key", 0); + $extension_config->clear("theme.$key"); // Remove the theme from the current list. unset($this->list[$key]); @@ -341,14 +350,17 @@ public function disable(array $theme_list) { // @todo Remove system_list(). $this->systemListReset(); + + // Remove all configuration belonging to the theme. + $this->configManager->uninstall('theme', $key); + } $extension_config->save(); $this->state->set('system.theme.data', $current_theme_data); $this->resetSystem(); - // Invoke hook_themes_disabled after the themes have been disabled. - $this->moduleHandler->invokeAll('themes_disabled', array($theme_list)); + $this->moduleHandler->invokeAll('themes_uninstalled', [$theme_list]); } /** @@ -400,13 +412,13 @@ public function addTheme(Extension $theme) { public function refreshInfo() { $this->reset(); $extension_config = $this->configFactory->get('core.extension'); - $enabled = $extension_config->get('theme'); + $installed = $extension_config->get('theme'); // @todo Avoid re-scanning all themes by retaining the original (unaltered) // theme info somewhere. $list = $this->rebuildThemeData(); foreach ($list as $name => $theme) { - if (isset($enabled[$name])) { + if (isset($installed[$name])) { $this->addTheme($theme); } } @@ -429,7 +441,7 @@ public function rebuildThemeData() { $themes = $listing->scan('theme'); $engines = $listing->scan('theme_engine'); $extension_config = $this->configFactory->get('core.extension'); - $enabled = $extension_config->get('theme') ?: array(); + $installed = $extension_config->get('theme') ?: array(); // Set defaults for theme info. $defaults = array( @@ -458,7 +470,7 @@ public function rebuildThemeData() { // Read info files for each theme. foreach ($themes as $key => $theme) { // @todo Remove all code that relies on the $status property. - $theme->status = (int) isset($enabled[$key]); + $theme->status = (int) isset($installed[$key]); $theme->info = $this->infoParser->parse($theme->getPathname()) + $defaults; diff --git a/core/lib/Drupal/Core/Extension/ThemeHandlerInterface.php b/core/lib/Drupal/Core/Extension/ThemeHandlerInterface.php index 74f9ad2..aa198d6 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandlerInterface.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandlerInterface.php @@ -8,49 +8,54 @@ namespace Drupal\Core\Extension; /** - * Manages the list of available themes as well as enable/disable them. + * Manages the list of available themes as well as install/uninstall them. */ interface ThemeHandlerInterface { /** - * Enables a given list of themes. + * Installs a given list of themes. * * @param array $theme_list * An array of theme names. - * @param bool $enable_dependencies + * @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 enabled. + * Whether any of the given themes have been installed. * * @throws \Drupal\Core\Extension\ExtensionNameLengthException * Thrown when the theme name is to long */ - public function enable(array $theme_list, $enable_dependencies = TRUE); + public function install(array $theme_list, $install_dependencies = TRUE); /** - * Disables a given list of themes. + * 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 - * An array of theme names. + * The themes to uninstall. * - * @return bool - * Whether any of the given themes have been disabled. + * @throws \InvalidArgumentException + * Thrown when you uninstall an not installed theme. + * + * @see hook_themes_uninstalled() */ - public function disable(array $theme_list); + public function uninstall(array $theme_list); /** - * Returns a list of currently enabled themes. + * Returns a list of currently installed themes. * * @return \Drupal\Core\Extension\Extension[] - * An associative array of the currently enabled themes. The keys are the + * An associative array of the currently installed themes. The keys are the * themes' machine names and the values are objects having the following * properties: * - filename: The filepath and name of the .info.yml file. * - name: The machine name of the theme. - * - status: 1 for enabled, 0 for disabled themes. + * - status: 1 for installed, 0 for uninstalled themes. * - info: The contents of the .info.yml file. * - stylesheets: A two dimensional array, using the first key for the * media attribute (e.g. 'all'), the second for the name of the file @@ -83,7 +88,7 @@ public function disable(array $theme_list); public function listInfo(); /** - * Refreshes the theme info data of currently enabled themes. + * Refreshes the theme info data of currently installed themes. * * Modules can alter theme info, so this is typically called after a module * has been installed or uninstalled. @@ -140,7 +145,17 @@ public function getName($theme); public function getDefault(); /** - * Returns an array of directories for all enabled themes. + * Sets a new default theme. + * + * @param string $theme + * The new default theme. + * + * @return $this + */ + public function setDefault($theme); + + /** + * Returns an array of directories for all installed themes. * * Useful for tasks such as finding a file that exists in all theme * directories. @@ -150,13 +165,13 @@ public function getDefault(); public function getThemeDirectories(); /** - * Determines whether a given theme is enabled. + * Determines whether a given theme is installed. * * @param string $theme * The name of the theme (without the .theme extension). * * @return bool - * TRUE if the theme is both installed and enabled. + * TRUE if the theme is installed. */ public function themeExists($theme); diff --git a/core/lib/Drupal/Core/Theme/ThemeAccessCheck.php b/core/lib/Drupal/Core/Theme/ThemeAccessCheck.php index 6c2a4c1..2927756 100644 --- a/core/lib/Drupal/Core/Theme/ThemeAccessCheck.php +++ b/core/lib/Drupal/Core/Theme/ThemeAccessCheck.php @@ -30,13 +30,13 @@ public function access($theme) { } /** - * Indicates whether the theme is accessible based on whether it is enabled. + * Indicates whether the theme is accessible based on whether it is installed. * * @param string $theme * The name of a theme. * * @return bool - * TRUE if the theme is enabled, FALSE otherwise. + * TRUE if the theme is installed, FALSE otherwise. */ public function checkAccess($theme) { $themes = list_themes(); diff --git a/core/lib/Drupal/Core/Theme/ThemeInitialization.php b/core/lib/Drupal/Core/Theme/ThemeInitialization.php index c6d800e..d4e1d95 100644 --- a/core/lib/Drupal/Core/Theme/ThemeInitialization.php +++ b/core/lib/Drupal/Core/Theme/ThemeInitialization.php @@ -64,15 +64,15 @@ public function getActiveThemeByName($theme_name) { $themes = $this->themeHandler->listInfo(); // If no theme could be negotiated, or if the negotiated theme is not within - // the list of enabled themes, fall back to the default theme output of core - // and modules (like Stark, but without a theme extension at all). This is - // possible, because loadActiveTheme() always loads the Twig theme engine. - // This is desired, because missing or malformed theme configuration should - // not leave the application in a broken state. By falling back to default - // output, the user is able to reconfigure the theme through the UI. + // the list of installed themes, fall back to the default theme output of + // core and modules (like Stark, but without a theme extension at all). This + // is possible, because loadActiveTheme() always loads the Twig theme + // engine. This is desired, because missing or malformed theme configuration + // should not leave the application in a broken state. By falling back to + // default output, the user is able to reconfigure the theme through the UI. // Lastly, tests are expected to operate with no theme by default, so as to // only assert the original theme output of modules (unless a test manually - // enables a specific theme). + // installs a specific theme). if (empty($themes) || !$theme_name || !isset($themes[$theme_name])) { $theme_name = 'core'; // /core/core.info.yml does not actually exist, but is required because diff --git a/core/lib/Drupal/Core/Updater/Theme.php b/core/lib/Drupal/Core/Updater/Theme.php index 4bd716a..7e17ddd 100644 --- a/core/lib/Drupal/Core/Updater/Theme.php +++ b/core/lib/Drupal/Core/Updater/Theme.php @@ -82,7 +82,7 @@ public function postInstall() { */ public function postInstallTasks() { return array( - l(t('Enable newly added themes'), 'admin/appearance'), + l(t('Install newly added themes'), 'admin/appearance'), l(t('Administration pages'), 'admin'), ); } diff --git a/core/lib/Drupal/Core/Utility/ProjectInfo.php b/core/lib/Drupal/Core/Utility/ProjectInfo.php index 2a49c8c..dd64510 100644 --- a/core/lib/Drupal/Core/Utility/ProjectInfo.php +++ b/core/lib/Drupal/Core/Utility/ProjectInfo.php @@ -19,6 +19,10 @@ class ProjectInfo { /** * Populates an array of project data. * + * @todo https://www.drupal.org/node/2338167 update class since extensions can + * no longer be hidden, enabled or disabled. Additionally base themes have + * to be installed for sub themes. to work. + * * This iterates over a list of the installed modules or themes and groups * them by project and status. A few parts of this function assume that * enabled modules and themes are always processed first, and if disabled @@ -51,15 +55,15 @@ function processInfoList(array &$projects, array $list, $project_type, $status, // projects list. if ($status && !empty($file->sub_themes)) { foreach ($file->sub_themes as $key => $name) { - // Build a list of enabled sub-themes. + // Build a list of installed sub-themes. if ($list[$key]->status) { - $file->enabled_sub_themes[$key] = $name; + $file->installed_sub_themes[$key] = $name; } } - // If the theme is disabled and there are no enabled subthemes, we - // should ignore this base theme for the enabled case. If the site is - // trying to display disabled themes, we'll catch it then. - if (!$file->status && empty($file->enabled_sub_themes)) { + // If the theme is uninstalled and there are no installed subthemes, we + // should ignore this base theme for the installed case. If the site is + // trying to display uninstalled themes, we'll catch it then. + if (!$file->status && empty($file->installed_sub_themes)) { continue; } } @@ -73,8 +77,9 @@ function processInfoList(array &$projects, array $list, $project_type, $status, continue; } - // Skip if it's a hidden module or hidden theme without enabled sub-themes. - if (!empty($file->info['hidden']) && empty($file->enabled_sub_themes)) { + // Skip if it's a hidden module or hidden theme without installed + // sub-themes. + if (!empty($file->info['hidden']) && empty($file->installed_sub_themes)) { continue; } @@ -115,10 +120,10 @@ function processInfoList(array &$projects, array $list, $project_type, $status, else { $project_display_type = $project_type; } - if (empty($status) && empty($file->enabled_sub_themes)) { + if (empty($status) && empty($file->installed_sub_themes)) { // If we're processing disabled modules or themes, append a suffix. - // However, we don't do this to a a base theme with enabled - // subthemes, since we treat that case as if it is enabled. + // However, we don't do this to a base theme with installed + // subthemes, since we treat that case as if it is installed. $project_display_type .= '-disabled'; } // Add a list of sub-themes that "depend on" the project and a list of base @@ -129,8 +134,8 @@ function processInfoList(array &$projects, array $list, $project_type, $status, $base_themes = array(); } else { - // Add list of enabled sub-themes. - $sub_themes = !empty($file->enabled_sub_themes) ? $file->enabled_sub_themes : array(); + // Add list of installed sub-themes. + $sub_themes = !empty($file->installed_sub_themes) ? $file->installed_sub_themes : array(); // Add list of base themes. $base_themes = !empty($file->base_themes) ? $file->base_themes : array(); } diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 339d163..99b9730 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -27,7 +27,7 @@ function block_help($route_name, RouteMatchInterface $route_match) { $output .= '
' . t('Demonstrating block regions for a theme') . '
'; $output .= '
' . t('You can see which region is where in a theme by clicking an the Demonstrate block regions link on the Block layout page. Regions are specific to each theme, so you need to toggle to a different theme first to demonstrate its block regions.', array('!blocks' => \Drupal::url('block.admin_display'))) . '
'; $output .= '
' . t('Toggling between different themes') . '
'; - $output .= '
' . t('Blocks are placed and configured specifically for each theme. The Block layout page opens with the default theme, but you can toggle to other enabled themes.') . '
'; + $output .= '
' . t('Blocks are placed and configured specifically for each theme. The Block layout page opens with the default theme, but you can toggle to other installed themes.') . '
'; $output .= '
' . t('Configuring block settings') . '
'; $output .= '
' . t('To change the settings of an individual block click on the Configure link on the Block layout page. The available options vary depending on the module that provides the block. For all blocks you can change the block title and toggle whether to display it.', array('!blocks' => Drupal::url('block.admin_display'))) . '
'; $output .= '
' . t('Controlling visibility') . '
'; @@ -150,12 +150,12 @@ function _block_rehash($theme = NULL) { } /** - * Initializes blocks for enabled themes. + * Initializes blocks for installed themes. * * @param $theme_list * An array of theme names. */ -function block_themes_enabled($theme_list) { +function block_themes_installed($theme_list) { foreach ($theme_list as $theme) { block_theme_initialize($theme); } @@ -164,9 +164,9 @@ function block_themes_enabled($theme_list) { /** * Assigns an initial, default set of blocks for a theme. * - * This function is called the first time a new theme is enabled. The new theme - * gets a copy of the default theme's blocks, with the difference that if a - * particular region isn't available in the new theme, the block is assigned + * This function is called the first time a new theme is installed. The new + * theme gets a copy of the default theme's blocks, with the difference that if + * a particular region isn't available in the new theme, the block is assigned * to the new theme's default region. * * @param $theme diff --git a/core/modules/block/src/Tests/BlockAdminThemeTest.php b/core/modules/block/src/Tests/BlockAdminThemeTest.php index 20b892c..9a86f29 100644 --- a/core/modules/block/src/Tests/BlockAdminThemeTest.php +++ b/core/modules/block/src/Tests/BlockAdminThemeTest.php @@ -31,12 +31,13 @@ function testAdminTheme() { $admin_user = $this->drupalCreateUser(array('administer blocks', 'administer themes')); $this->drupalLogin($admin_user); - // Ensure that access to block admin page is denied when theme is disabled. + // Ensure that access to block admin page is denied when theme is not + // installed. $this->drupalGet('admin/structure/block/list/bartik'); $this->assertResponse(403); - // Enable admin theme and confirm that tab is accessible. - theme_enable(array('bartik')); + // Install admin theme and confirm that tab is accessible. + \Drupal::service('theme_handler')->install(array('bartik')); $edit['admin_theme'] = 'bartik'; $this->drupalPostForm('admin/appearance', $edit, t('Save configuration')); $this->drupalGet('admin/structure/block/list/bartik'); diff --git a/core/modules/block/src/Tests/BlockHiddenRegionTest.php b/core/modules/block/src/Tests/BlockHiddenRegionTest.php index c46d082..95b06f3 100644 --- a/core/modules/block/src/Tests/BlockHiddenRegionTest.php +++ b/core/modules/block/src/Tests/BlockHiddenRegionTest.php @@ -10,7 +10,7 @@ use Drupal\simpletest\WebTestBase; /** - * Tests that a newly enabled theme does not inherit blocks to its hidden + * Tests that a newly installed theme does not inherit blocks to its hidden * regions. * * @group block @@ -45,7 +45,7 @@ protected function setUp() { } /** - * Tests that hidden regions do not inherit blocks when a theme is enabled. + * Tests that hidden regions do not inherit blocks when a theme is installed. */ public function testBlockNotInHiddenRegion() { @@ -53,13 +53,13 @@ public function testBlockNotInHiddenRegion() { $this->drupalGet(''); $this->assertText('Search', 'Block was displayed on the front page.'); - // Enable "block_test_theme" and set it as the default theme. + // Install "block_test_theme" and set it as the default theme. $theme = 'block_test_theme'; - theme_enable(array($theme)); + \Drupal::service('theme_handler')->install(array($theme)); \Drupal::config('system.theme') ->set('default', $theme) ->save(); - // Enabling a theme will cause the kernel terminate event to rebuild the + // Installing a theme will cause the kernel terminate event to rebuild the // router. Simulate that here. \Drupal::service('router.builder')->rebuildIfNeeded(); diff --git a/core/modules/block/src/Tests/BlockTest.php b/core/modules/block/src/Tests/BlockTest.php index 6240fcd..234077c 100644 --- a/core/modules/block/src/Tests/BlockTest.php +++ b/core/modules/block/src/Tests/BlockTest.php @@ -154,8 +154,8 @@ function testBlock() { * Tests that the block form has a theme selector when not passed via the URL. */ public function testBlockThemeSelector() { - // Enable all themes. - theme_enable(array('bartik', 'seven')); + // Install all themes. + \Drupal::service('theme_handler')->install(array('bartik', 'seven')); $theme_settings = $this->container->get('config.factory')->get('system.theme'); foreach (array('bartik', 'stark', 'seven') as $theme) { $this->drupalGet('admin/structure/block/list/' . $theme); @@ -185,7 +185,7 @@ function testThemeName() { $this->drupalPlaceBlock('system_help_block', array('region' => 'help')); // Explicitly set the default and admin themes. $theme = 'block_test_specialchars_theme'; - theme_enable(array($theme)); + \Drupal::service('theme_handler')->install(array($theme)); \Drupal::service('router.builder')->rebuild(); $this->drupalGet('admin/structure/block'); $this->assertRaw(String::checkPlain('<"Cat" & \'Mouse\'>')); @@ -377,4 +377,24 @@ public function testBlockCacheTags() { $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS'); } + /** + * Tests that uninstalling a theme removes its block configuration. + */ + public function testUninstallTheme() { + /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */ + $theme_handler = \Drupal::service('theme_handler'); + + $theme_handler->install(['seven']); + $theme_handler->setDefault('seven'); + $block = $this->drupalPlaceBlock('system_powered_by_block', ['theme' => 'seven', 'region' => 'help']); + $this->drupalGet(''); + $this->assertText('Powered by Drupal'); + + $theme_handler->setDefault('stark'); + $theme_handler->uninstall(['seven']); + + // Ensure that the block configuration does not exist anymore. + $this->assertIdentical(NULL, Block::load($block->id())); + } + } diff --git a/core/modules/block/src/Tests/NewDefaultThemeBlocksTest.php b/core/modules/block/src/Tests/NewDefaultThemeBlocksTest.php index 9a6642c..8471976 100644 --- a/core/modules/block/src/Tests/NewDefaultThemeBlocksTest.php +++ b/core/modules/block/src/Tests/NewDefaultThemeBlocksTest.php @@ -42,10 +42,10 @@ function testNewDefaultThemeBlocks() { 'id' => $default_theme . '_' . strtolower($this->randomMachineName(8)), )); - // Enable a different theme. + // Install a different theme. $new_theme = 'bartik'; $this->assertFalse($new_theme == $default_theme, 'The new theme is different from the previous default theme.'); - theme_enable(array($new_theme)); + \Drupal::service('theme_handler')->install(array($new_theme)); \Drupal::config('system.theme') ->set('default', $new_theme) ->save(); diff --git a/core/modules/block/src/Tests/NonDefaultBlockAdminTest.php b/core/modules/block/src/Tests/NonDefaultBlockAdminTest.php index f7ffd37..c2e7e03 100644 --- a/core/modules/block/src/Tests/NonDefaultBlockAdminTest.php +++ b/core/modules/block/src/Tests/NonDefaultBlockAdminTest.php @@ -30,7 +30,7 @@ function testNonDefaultBlockAdmin() { $admin_user = $this->drupalCreateUser(array('administer blocks', 'administer themes')); $this->drupalLogin($admin_user); $new_theme = 'bartik'; - theme_enable(array($new_theme)); + \Drupal::service('theme_handler')->install(array($new_theme)); $this->drupalGet('admin/structure/block/list/' . $new_theme); $this->assertText('Bartik(' . t('active tab') . ')', 'Tab for non-default theme found.'); } diff --git a/core/modules/block_content/src/Tests/BlockContentTypeTest.php b/core/modules/block_content/src/Tests/BlockContentTypeTest.php index b36d009..8a20eec 100644 --- a/core/modules/block_content/src/Tests/BlockContentTypeTest.php +++ b/core/modules/block_content/src/Tests/BlockContentTypeTest.php @@ -142,8 +142,8 @@ public function testsBlockContentAddTypes() { ->get('entity.manager') ->getStorage('block_content'); - // Enable all themes. - theme_enable(array('bartik', 'seven')); + // Install all themes. + \Drupal::service('theme_handler')->install(array('bartik', 'seven')); $themes = array('bartik', 'seven', 'stark'); $theme_settings = $this->container->get('config.factory')->get('system.theme'); foreach ($themes as $default_theme) { @@ -151,7 +151,7 @@ public function testsBlockContentAddTypes() { $theme_settings->set('default', $default_theme)->save(); \Drupal::service('router.builder')->rebuild(); - // For each enabled theme, go to its block page and test the redirects. + // For each installed theme, go to its block page and test the redirects. $themes = array('bartik', 'stark', 'seven'); foreach ($themes as $theme) { // Test that adding a block from the 'place blocks' form sends you to the diff --git a/core/modules/breakpoint/breakpoint.module b/core/modules/breakpoint/breakpoint.module index 35187b1..eff0aef 100644 --- a/core/modules/breakpoint/breakpoint.module +++ b/core/modules/breakpoint/breakpoint.module @@ -37,15 +37,15 @@ function breakpoint_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_themes_enabled() + * Implements hook_themes_installed() */ -function breakpoint_themes_enabled($theme_list) { +function breakpoint_themes_installed($theme_list) { \Drupal::service('breakpoint.manager')->clearCachedDefinitions(); } /** - * Implements hook_themes_disabled() + * Implements hook_themes_uninstalled() */ -function breakpoint_themes_disabled($theme_list) { +function breakpoint_themes_uninstalled($theme_list) { \Drupal::service('breakpoint.manager')->clearCachedDefinitions(); } diff --git a/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php b/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php index c7dda94..a8a46f9 100644 --- a/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php +++ b/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php @@ -24,7 +24,7 @@ class BreakpointDiscoveryTest extends KernelTestBase { protected function setUp() { parent::setUp(); - \Drupal::service('theme_handler')->enable(array('breakpoint_theme_test')); + \Drupal::service('theme_handler')->install(array('breakpoint_theme_test')); } /** diff --git a/core/modules/color/src/Tests/ColorConfigSchemaTest.php b/core/modules/color/src/Tests/ColorConfigSchemaTest.php index 3b49e17..a5c9d33 100644 --- a/core/modules/color/src/Tests/ColorConfigSchemaTest.php +++ b/core/modules/color/src/Tests/ColorConfigSchemaTest.php @@ -38,7 +38,7 @@ class ColorConfigSchemaTest extends WebTestBase { */ protected function setUp() { parent::setUp(); - \Drupal::service('theme_handler')->enable(array('bartik')); + \Drupal::service('theme_handler')->install(array('bartik')); // Create user. $this->adminUser = $this->drupalCreateUser(array('administer themes')); diff --git a/core/modules/color/src/Tests/ColorTest.php b/core/modules/color/src/Tests/ColorTest.php index c7260a1..fb400a3 100644 --- a/core/modules/color/src/Tests/ColorTest.php +++ b/core/modules/color/src/Tests/ColorTest.php @@ -70,7 +70,7 @@ protected function setUp() { 'scheme_color' => '#3b3b3b', ), ); - theme_enable(array_keys($this->themes)); + \Drupal::service('theme_handler')->install(array_keys($this->themes)); // Array filled with valid and not valid color values. $this->colorTests = array( diff --git a/core/modules/comment/src/Tests/CommentLinksTest.php b/core/modules/comment/src/Tests/CommentLinksTest.php index 00484b6..34b8b41 100644 --- a/core/modules/comment/src/Tests/CommentLinksTest.php +++ b/core/modules/comment/src/Tests/CommentLinksTest.php @@ -47,7 +47,7 @@ class CommentLinksTest extends CommentTestBase { */ public function testCommentLinks() { // Bartik theme alters comment links, so use a different theme. - \Drupal::service('theme_handler')->enable(array('stark')); + \Drupal::service('theme_handler')->install(array('stark')); \Drupal::config('system.theme') ->set('default', 'stark') ->save(); diff --git a/core/modules/config/src/Tests/ConfigImportUITest.php b/core/modules/config/src/Tests/ConfigImportUITest.php index f5e4947..959b2f1 100644 --- a/core/modules/config/src/Tests/ConfigImportUITest.php +++ b/core/modules/config/src/Tests/ConfigImportUITest.php @@ -141,7 +141,7 @@ function testImport() { $this->assertTrue(\Drupal::moduleHandler()->moduleExists('text'), 'Text module installed during import.'); $theme_info = \Drupal::service('theme_handler')->listInfo(); - $this->assertTrue($theme_info['bartik']->status, 'Bartik theme enabled during import.'); + $this->assertTrue($theme_info['bartik']->status, 'Bartik theme installed during import.'); // Ensure installations and uninstallation occur as expected. $installed = \Drupal::state()->get('ConfigImportUITest.core.extension.modules_installed', array()); @@ -164,7 +164,6 @@ function testImport() { unset($core_extension['module']['options']); unset($core_extension['module']['text']); unset($core_extension['theme']['bartik']); - $core_extension['disabled']['theme']['bartik'] = 0; $staging->write('core.extension', $core_extension); $staging->delete('action.settings'); $staging->delete('text.settings'); @@ -205,7 +204,7 @@ function testImport() { $this->assertTrue(empty($installed), 'No modules installed during import'); $theme_info = \Drupal::service('theme_handler')->listInfo(); - $this->assertFalse(isset($theme_info['bartik']), 'Bartik theme disabled during import.'); + $this->assertFalse(isset($theme_info['bartik']), 'Bartik theme uninstalled during import.'); // Verify that the action.settings configuration object was only deleted // once during the import process. diff --git a/core/modules/config_translation/config_translation.module b/core/modules/config_translation/config_translation.module index 43aa754..8892bb5 100644 --- a/core/modules/config_translation/config_translation.module +++ b/core/modules/config_translation/config_translation.module @@ -61,9 +61,9 @@ function config_translation_theme() { } /** - * Implements hook_themes_enabled(). + * Implements hook_themes_installed(). */ -function config_translation_themes_enabled() { +function config_translation_themes_installed() { // Themes can provide *.config_translation.yml declarations. // @todo Make ThemeHandler trigger an event instead and make // ConfigMapperManager plugin manager subscribe to it. @@ -72,9 +72,9 @@ function config_translation_themes_enabled() { } /** - * Implements hook_themes_disabled(). + * Implements hook_themes_uninstalled(). */ -function config_translation_themes_disabled() { +function config_translation_themes_uninstalled() { // Themes can provide *.config_translation.yml declarations. // @todo Make ThemeHandler trigger an event instead and make // ConfigMapperManager plugin manager subscribe to it. diff --git a/core/modules/config_translation/src/ConfigMapperManager.php b/core/modules/config_translation/src/ConfigMapperManager.php index 6c99ce1..2335ffe 100644 --- a/core/modules/config_translation/src/ConfigMapperManager.php +++ b/core/modules/config_translation/src/ConfigMapperManager.php @@ -68,14 +68,14 @@ public function __construct(CacheBackendInterface $cache_backend, LanguageManage $this->typedConfigManager = $typed_config_manager; // Look at all themes and modules. - // @todo If the list of enabled modules and themes is changed, new + // @todo If the list of installed modules and themes is changed, new // definitions are not picked up immediately and obsolete definitions are // not removed, because the list of search directories is only compiled // once in this constructor. The current code only works due to - // coincidence: The request that enables e.g. a new theme does not + // coincidence: The request that installs e.g. a new theme does not // instantiate this plugin manager at the beginning of the request; when // routes are being rebuilt at the end of the request, this service only - // happens to get instantiated with the updated list of enabled themes. + // happens to get instantiated with the updated list of installed themes. $directories = array(); foreach ($module_handler->getModuleList() as $name => $module) { $directories[$name] = $module->getPath(); diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationUiThemeTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationUiThemeTest.php index bb39379..7aa8205 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationUiThemeTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationUiThemeTest.php @@ -60,14 +60,14 @@ protected function setUp() { * Tests that theme provided *.config_translation.yml files are found. */ public function testThemeDiscovery() { - // Enable the test theme and rebuild routes. + // Install the test theme and rebuild routes. $theme = 'config_translation_test_theme'; $this->drupalLogin($this->admin_user); $this->drupalGet('admin/appearance'); $elements = $this->xpath('//a[normalize-space()=:label and contains(@href, :theme)]', array( - ':label' => 'Enable and set as default', + ':label' => 'Install and set as default', ':theme' => $theme, )); $this->drupalGet($GLOBALS['base_root'] . $elements[0]['href'], array('external' => TRUE)); diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 3122f59..6acc1cf 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -355,20 +355,17 @@ function locale_modules_uninstalled($modules) { } /** - * Implements hook_themes_enabled(). - * - * @todo This is technically wrong. We must not import upon enabling, but upon - * initial installation. The theme system is missing an installation hook. + * Implements hook_themes_installed(). */ -function locale_themes_enabled($themes) { +function locale_themes_installed($themes) { $components['theme'] = $themes; locale_system_update($components); } /** - * Implements hook_themes_disabled(). + * Implements hook_themes_uninstalled(). */ -function locale_themes_disabled($themes) { +function locale_themes_uninstalled($themes) { $components['theme'] = $themes; locale_system_remove($components); } diff --git a/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php b/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php index 3a3e027..a876fb3 100644 --- a/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php +++ b/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php @@ -70,7 +70,7 @@ function testTranslationLinkTheme() { $entityId = $this->createEntity(array(), 'en'); // Set up Seven as the admin theme to test. - $this->container->get('theme_handler')->enable(array('seven')); + $this->container->get('theme_handler')->install(array('seven')); $edit = array(); $edit['admin_theme'] = 'seven'; $this->drupalPostForm('admin/appearance', $edit, t('Save configuration')); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockTest.php index d8bf38c..4b15b05 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockTest.php @@ -65,8 +65,8 @@ protected function setUp() { $config->set('admin', 'seven'); $config->save(); - // Enable one of D8's test themes. - \Drupal::service('theme_handler')->enable(array('test_theme')); + // Install one of D8's test themes. + \Drupal::service('theme_handler')->install(array('test_theme')); /** @var \Drupal\migrate\entity\Migration $migration */ $migration = entity_load('migration', 'd6_block'); diff --git a/core/modules/node/src/Tests/NodeTranslationUITest.php b/core/modules/node/src/Tests/NodeTranslationUITest.php index 7d3c651..4ff7014 100644 --- a/core/modules/node/src/Tests/NodeTranslationUITest.php +++ b/core/modules/node/src/Tests/NodeTranslationUITest.php @@ -182,7 +182,7 @@ function testTranslationLinkTheme() { $article = $this->drupalCreateNode(array('type' => 'article', 'langcode' => $this->langcodes[0])); // Set up Seven as the admin theme and use it for node editing. - $this->container->get('theme_handler')->enable(array('seven')); + $this->container->get('theme_handler')->install(array('seven')); $edit = array(); $edit['admin_theme'] = 'seven'; $edit['use_admin_theme'] = TRUE; diff --git a/core/modules/responsive_image/src/ResponsiveImageMappingForm.php b/core/modules/responsive_image/src/ResponsiveImageMappingForm.php index 6e35126..0ad61ca 100644 --- a/core/modules/responsive_image/src/ResponsiveImageMappingForm.php +++ b/core/modules/responsive_image/src/ResponsiveImageMappingForm.php @@ -84,10 +84,10 @@ public function form(array $form, FormStateInterface $form_state) { ); if ((bool) $responsive_image_mapping->id() && $this->operation != 'duplicate') { - $description = $this->t('Select a breakpoint group from the enabled themes.') . ' ' . $this->t("Warning: if you change the breakpoint group you lose all your selected mappings."); + $description = $this->t('Select a breakpoint group from the installed themes.') . ' ' . $this->t("Warning: if you change the breakpoint group you lose all your selected mappings."); } else { - $description = $this->t('Select a breakpoint group from the enabled themes.'); + $description = $this->t('Select a breakpoint group from the installed themes.'); } $form['breakpointGroup'] = array( '#type' => 'select', diff --git a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php index 2b4c731..24c5550 100644 --- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php @@ -99,7 +99,7 @@ public function testShortcutLinkAdd() { * Tests that the "add to shortcut" and "remove from shortcut" links work. */ public function testShortcutQuickLink() { - theme_enable(array('seven')); + \Drupal::service('theme_handler')->install(array('seven')); \Drupal::config('system.theme')->set('admin', 'seven')->save(); $this->container->get('config.factory')->get('node.settings')->set('use_admin_theme', '1')->save(); $this->container->get('router.builder')->rebuild(); @@ -202,7 +202,7 @@ public function testShortcutLinkDelete() { */ public function testNoShortcutLink() { // Change to a theme that displays shortcuts. - theme_enable(array('seven')); + \Drupal::service('theme_handler')->install(array('seven')); \Drupal::config('system.theme') ->set('default', 'seven') ->save(); @@ -233,7 +233,7 @@ public function testNoShortcutLink() { */ public function testAccessShortcutsPermission() { // Change to a theme that displays shortcuts. - \Drupal::service('theme_handler')->enable(array('seven')); + \Drupal::service('theme_handler')->install(array('seven')); \Drupal::config('system.theme') ->set('default', 'seven') ->save(); diff --git a/core/modules/system/css/system.admin.css b/core/modules/system/css/system.admin.css index 0031327..853ded2 100644 --- a/core/modules/system/css/system.admin.css +++ b/core/modules/system/css/system.admin.css @@ -219,7 +219,7 @@ table.system-status-report .status-title { .system-themes-list { margin-bottom: 20px; } -.system-themes-list-disabled { +.system-themes-list-uninstalled { border-top: 1px solid #cdcdcd; padding-top: 20px; } @@ -241,8 +241,8 @@ table.system-status-report .status-title { .theme-default .screenshot { border: 1px solid #aaa; } -.system-themes-list-disabled .screenshot, -.system-themes-list-disabled .no-screenshot { +.system-themes-list-uninstalled .screenshot, +.system-themes-list-uninstalled .no-screenshot { max-width: 194px; height: auto; } @@ -257,31 +257,31 @@ table.system-status-report .status-title { * Theme display without vertical toolbar. */ @media screen and (min-width: 45em) { - body:not(.toolbar-vertical) .system-themes-list-enabled .screenshot, - body:not(.toolbar-vertical) .system-themes-list-enabled .no-screenshot { + body:not(.toolbar-vertical) .system-themes-list-installed .screenshot, + body:not(.toolbar-vertical) .system-themes-list-installed .no-screenshot { float: left; /* LTR */ margin: 0 20px 0 0; /* LTR */ width: 294px; } - [dir="rtl"] body:not(.toolbar-vertical) .system-themes-list-enabled .screenshot, - [dir="rtl"] body:not(.toolbar-vertical) .system-themes-list-enabled .no-screenshot { + [dir="rtl"] body:not(.toolbar-vertical) .system-themes-list-installed .screenshot, + [dir="rtl"] body:not(.toolbar-vertical) .system-themes-list-installed .no-screenshot { float: right; margin: 0 0 0 20px; } - body:not(.toolbar-vertical) .system-themes-list-enabled h3 { + body:not(.toolbar-vertical) .system-themes-list-installed h3 { margin-top: 0; } - body:not(.toolbar-vertical) .system-themes-list-disabled .theme-selector { + body:not(.toolbar-vertical) .system-themes-list-uninstalled .theme-selector { box-sizing: border-box; width: 31.25%; float: left; /* LTR */ padding: 20px 20px 20px 0; /* LTR */ } - [dir="rtl"] body:not(.toolbar-vertical) .system-themes-list-disabled .theme-selector { + [dir="rtl"] body:not(.toolbar-vertical) .system-themes-list-uninstalled .theme-selector { float: right; padding: 20px 0 20px 20px; } - body:not(.toolbar-vertical) .system-themes-list-disabled .theme-info { + body:not(.toolbar-vertical) .system-themes-list-uninstalled .theme-info { min-height: 170px; } } @@ -290,35 +290,35 @@ table.system-status-report .status-title { * Theme display with vertical toolbar. */ @media screen and (min-width: 60em) { - .toolbar-vertical .system-themes-list-enabled .screenshot, - .toolbar-vertical .system-themes-list-enabled .no-screenshot { + .toolbar-vertical .system-themes-list-installed .screenshot, + .toolbar-vertical .system-themes-list-installed .no-screenshot { float: left; /* LTR */ margin: 0 20px 0 0; /* LTR */ width: 294px; } - [dir="rtl"] .toolbar-vertical .system-themes-list-enabled .screenshot, - [dir="rtl"] .toolbar-vertical .system-themes-list-enabled .no-screenshot { + [dir="rtl"] .toolbar-vertical .system-themes-list-installed .screenshot, + [dir="rtl"] .toolbar-vertical .system-themes-list-installed .no-screenshot { float: right; margin: 0 0 0 20px; } - .toolbar-vertical .system-themes-list-enabled h3 { + .toolbar-vertical .system-themes-list-installed h3 { margin-top: 0; } - .toolbar-vertical .system-themes-list-disabled .theme-selector { + .toolbar-vertical .system-themes-list-uninstalled .theme-selector { box-sizing: border-box; width: 31.25%; float: left; /* LTR */ padding: 20px 20px 20px 0; /* LTR */ } - [dir="rtl"] .toolbar-vertical .system-themes-list-disabled .theme-selector { + [dir="rtl"] .toolbar-vertical .system-themes-list-uninstalled .theme-selector { float: right; padding: 20px 0 20px 20px; } - .toolbar-vertical .system-themes-list-disabled .theme-info { + .toolbar-vertical .system-themes-list-uninstalled .theme-info { min-height: 170px; } } -.system-themes-list-enabled .theme-info { +.system-themes-list-installed .theme-info { max-width: 940px; } diff --git a/core/modules/system/src/Controller/SystemController.php b/core/modules/system/src/Controller/SystemController.php index 605b0a9..4f1b2f1 100644 --- a/core/modules/system/src/Controller/SystemController.php +++ b/core/modules/system/src/Controller/SystemController.php @@ -191,7 +191,7 @@ public function themesPage() { uasort($themes, 'system_sort_modules_by_info_name'); $theme_default = $config->get('default'); - $theme_groups = array('enabled' => array(), 'disabled' => array()); + $theme_groups = array('installed' => array(), 'uninstalled' => array()); $admin_theme = $config->get('admin'); $admin_theme_options = array(); @@ -251,10 +251,10 @@ public function themesPage() { if (!$theme->is_default) { if ($theme->getName() != $admin_theme) { $theme->operations[] = array( - 'title' => $this->t('Disable'), - 'route_name' => 'system.theme_disable', + 'title' => $this->t('Uninstall'), + 'route_name' => 'system.theme_uninstall', 'query' => $query, - 'attributes' => array('title' => $this->t('Disable !theme theme', array('!theme' => $theme->info['name']))), + 'attributes' => array('title' => $this->t('Uninstall !theme theme', array('!theme' => $theme->info['name']))), ); } $theme->operations[] = array( @@ -268,16 +268,16 @@ public function themesPage() { } else { $theme->operations[] = array( - 'title' => $this->t('Enable'), - 'route_name' => 'system.theme_enable', + 'title' => $this->t('Install'), + 'route_name' => 'system.theme_install', 'query' => $query, - 'attributes' => array('title' => $this->t('Enable !theme theme', array('!theme' => $theme->info['name']))), + 'attributes' => array('title' => $this->t('Install !theme theme', array('!theme' => $theme->info['name']))), ); $theme->operations[] = array( - 'title' => $this->t('Enable and set as default'), + 'title' => $this->t('Install and set as default'), 'route_name' => 'system.theme_set_default', 'query' => $query, - 'attributes' => array('title' => $this->t('Enable !theme as default theme', array('!theme' => $theme->info['name']))), + 'attributes' => array('title' => $this->t('Install !theme as default theme', array('!theme' => $theme->info['name']))), ); } } @@ -294,19 +294,19 @@ public function themesPage() { $theme->notes[] = $this->t('admin theme'); } - // Sort enabled and disabled themes into their own groups. - $theme_groups[$theme->status ? 'enabled' : 'disabled'][] = $theme; + // Sort installed and uninstalled themes into their own groups. + $theme_groups[$theme->status ? 'installed' : 'uninstalled'][] = $theme; } // There are two possible theme groups. $theme_group_titles = array( - 'enabled' => $this->formatPlural(count($theme_groups['enabled']), 'Enabled theme', 'Enabled themes'), + 'installed' => $this->formatPlural(count($theme_groups['installed']), 'Installed theme', 'Installed themes'), ); - if (!empty($theme_groups['disabled'])) { - $theme_group_titles['disabled'] = $this->formatPlural(count($theme_groups['disabled']), 'Disabled theme', 'Disabled themes'); + if (!empty($theme_groups['uninstalled'])) { + $theme_group_titles['uninstalled'] = $this->formatPlural(count($theme_groups['uninstalled']), 'Uninstalled theme', 'Uninstalled themes'); } - uasort($theme_groups['enabled'], 'system_sort_themes'); + uasort($theme_groups['installed'], 'system_sort_themes'); $this->moduleHandler()->alter('system_themes_page', $theme_groups); $build = array(); diff --git a/core/modules/system/src/Controller/ThemeController.php b/core/modules/system/src/Controller/ThemeController.php index 51d91f9..fb98842 100644 --- a/core/modules/system/src/Controller/ThemeController.php +++ b/core/modules/system/src/Controller/ThemeController.php @@ -57,7 +57,7 @@ public static function create(ContainerInterface $container) { } /** - * Disables a theme. + * Uninstalls a theme. * * @param \Symfony\Component\HttpFoundation\Request $request * A request object containing a theme name and a valid token. @@ -69,7 +69,7 @@ public static function create(ContainerInterface $container) { * Throws access denied when no theme or token is set in the request or when * the token is invalid. */ - public function disable(Request $request) { + public function uninstall(Request $request) { $theme = $request->get('theme'); $config = $this->config('system.theme'); @@ -79,13 +79,13 @@ public function disable(Request $request) { // Check if the specified theme is one recognized by the system. if (!empty($themes[$theme])) { - // Do not disable the default or admin theme. + // Do not uninstall the default or admin theme. if ($theme === $config->get('default') || $theme === $config->get('admin')) { - drupal_set_message($this->t('%theme is the default theme and cannot be disabled.', array('%theme' => $themes[$theme]->info['name'])), 'error'); + drupal_set_message($this->t('%theme is the default theme and cannot be uninstalled.', array('%theme' => $themes[$theme]->info['name'])), 'error'); } else { - $this->themeHandler->disable(array($theme)); - drupal_set_message($this->t('The %theme theme has been disabled.', array('%theme' => $themes[$theme]->info['name']))); + $this->themeHandler->uninstall(array($theme)); + drupal_set_message($this->t('The %theme theme has been uninstalled.', array('%theme' => $themes[$theme]->info['name']))); } } else { @@ -99,7 +99,7 @@ public function disable(Request $request) { } /** - * Enables a theme. + * Installs a theme. * * @param \Symfony\Component\HttpFoundation\Request $request * A request object containing a theme name and a valid token. @@ -111,13 +111,13 @@ public function disable(Request $request) { * Throws access denied when no theme or token is set in the request or when * the token is invalid. */ - public function enable(Request $request) { + public function install(Request $request) { $theme = $request->get('theme'); if (isset($theme)) { - if ($this->themeHandler->enable(array($theme))) { + if ($this->themeHandler->install(array($theme))) { $themes = $this->themeHandler->listInfo(); - drupal_set_message($this->t('The %theme theme has been enabled.', array('%theme' => $themes[$theme]->info['name']))); + drupal_set_message($this->t('The %theme theme has been installed.', array('%theme' => $themes[$theme]->info['name']))); } else { drupal_set_message($this->t('The %theme theme was not found.', array('%theme' => $theme)), 'error'); @@ -150,8 +150,8 @@ public function setDefaultTheme(Request $request) { $themes = $this->themeHandler->listInfo(); // Check if the specified theme is one recognized by the system. - // Or try to enable the theme. - if (isset($themes[$theme]) || $this->themeHandler->enable(array($theme))) { + // Or try to install the theme. + if (isset($themes[$theme]) || $this->themeHandler->install(array($theme))) { $themes = $this->themeHandler->listInfo(); // Set the default theme. diff --git a/core/modules/system/src/Form/ThemeSettingsForm.php b/core/modules/system/src/Form/ThemeSettingsForm.php index b65628a..383f7ac 100644 --- a/core/modules/system/src/Form/ThemeSettingsForm.php +++ b/core/modules/system/src/Form/ThemeSettingsForm.php @@ -71,7 +71,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $theme = $themes = list_themes(); - // Deny access if the theme is disabled or not found. + // Deny access if the theme is not installed or not found. if (!empty($theme) && (empty($themes[$theme]) || !$themes[$theme]->status)) { throw new NotFoundHttpException(); } diff --git a/core/modules/system/src/Tests/Ajax/FrameworkTest.php b/core/modules/system/src/Tests/Ajax/FrameworkTest.php index 340b597..0928c2a 100644 --- a/core/modules/system/src/Tests/Ajax/FrameworkTest.php +++ b/core/modules/system/src/Tests/Ajax/FrameworkTest.php @@ -218,7 +218,7 @@ public function testCurrentPathChange() { public function testLazyLoadOverriddenCSS() { // The test theme overrides system.module.css without an implementation, // thereby removing it. - theme_enable(array('test_theme')); + \Drupal::service('theme_handler')->install(array('test_theme')); \Drupal::config('system.theme') ->set('default', 'test_theme') ->save(); diff --git a/core/modules/system/src/Tests/Batch/PageTest.php b/core/modules/system/src/Tests/Batch/PageTest.php index 1a30c6c..42800b7 100644 --- a/core/modules/system/src/Tests/Batch/PageTest.php +++ b/core/modules/system/src/Tests/Batch/PageTest.php @@ -29,7 +29,7 @@ class PageTest extends WebTestBase { function testBatchProgressPageTheme() { // Make sure that the page which starts the batch (an administrative page) // is using a different theme than would normally be used by the batch API. - $this->container->get('theme_handler')->enable(array('seven', 'bartik')); + $this->container->get('theme_handler')->install(array('seven', 'bartik')); $this->container->get('config.factory')->get('system.theme') ->set('default', 'bartik') ->set('admin', 'seven') diff --git a/core/modules/system/src/Tests/Common/AlterTest.php b/core/modules/system/src/Tests/Common/AlterTest.php index 40b3193..a0eb95b 100644 --- a/core/modules/system/src/Tests/Common/AlterTest.php +++ b/core/modules/system/src/Tests/Common/AlterTest.php @@ -29,7 +29,7 @@ class AlterTest extends WebTestBase { function testDrupalAlter() { // This test depends on Bartik, so make sure that it is always the current // active theme. - \Drupal::service('theme_handler')->enable(array('bartik')); + \Drupal::service('theme_handler')->install(array('bartik')); \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('bartik')); $array = array('foo' => 'bar'); diff --git a/core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php b/core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php index 26dd6ea..a8d0487 100644 --- a/core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php +++ b/core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php @@ -26,7 +26,7 @@ class CurrentThemeConditionTest extends KernelTestBase { * Tests the current theme condition. */ public function testCurrentTheme() { - \Drupal::service('theme_handler')->enable(array('test_theme')); + \Drupal::service('theme_handler')->install(array('test_theme')); $manager = \Drupal::service('plugin.manager.condition'); /** @var $condition \Drupal\Core\Condition\ConditionInterface */ diff --git a/core/modules/system/src/Tests/Extension/ThemeHandlerTest.php b/core/modules/system/src/Tests/Extension/ThemeHandlerTest.php index f652bfd..619736b 100644 --- a/core/modules/system/src/Tests/Extension/ThemeHandlerTest.php +++ b/core/modules/system/src/Tests/Extension/ThemeHandlerTest.php @@ -12,7 +12,7 @@ use Drupal\simpletest\DrupalUnitTestBase; /** - * Tests installing/enabling, disabling, and uninstalling of themes. + * Tests installing and uninstalling of themes. * * @group Extension */ @@ -39,11 +39,10 @@ protected function setUp() { } /** - * Verifies that no themes are installed/enabled/disabled by default. + * Verifies that no themes are installed by default. */ function testEmpty() { $this->assertFalse($this->extensionConfig()->get('theme')); - $this->assertFalse($this->extensionConfig()->get('disabled.theme')); $this->assertFalse(array_keys($this->themeHandler()->listInfo())); $this->assertFalse(array_keys(system_list('theme'))); @@ -56,18 +55,17 @@ function testEmpty() { } /** - * Tests enabling a theme. + * Tests installing a theme. */ - function testEnable() { + function testInstall() { $name = 'test_basetheme'; $themes = $this->themeHandler()->listInfo(); $this->assertFalse(isset($themes[$name])); - $this->themeHandler()->enable(array($name)); + $this->themeHandler()->install(array($name)); $this->assertIdentical($this->extensionConfig()->get("theme.$name"), 0); - $this->assertNull($this->extensionConfig()->get("disabled.theme.$name")); $themes = $this->themeHandler()->listInfo(); $this->assertTrue(isset($themes[$name])); @@ -82,22 +80,22 @@ function testEnable() { } /** - * Tests enabling a sub-theme. + * Tests installing a sub-theme. */ - function testEnableSubTheme() { + function testInstallSubTheme() { $name = 'test_subtheme'; $base_name = 'test_basetheme'; $themes = $this->themeHandler()->listInfo(); $this->assertFalse(array_keys($themes)); - $this->themeHandler()->enable(array($name)); + $this->themeHandler()->install(array($name)); $themes = $this->themeHandler()->listInfo(); $this->assertTrue(isset($themes[$name])); $this->assertTrue(isset($themes[$base_name])); - $this->themeHandler()->disable(array($name)); + $this->themeHandler()->uninstall(array($name)); $themes = $this->themeHandler()->listInfo(); $this->assertFalse(isset($themes[$name])); @@ -105,17 +103,17 @@ function testEnableSubTheme() { } /** - * Tests enabling a non-existing theme. + * Tests installing a non-existing theme. */ - function testEnableNonExisting() { + function testInstallNonExisting() { $name = 'non_existing_theme'; $themes = $this->themeHandler()->listInfo(); $this->assertFalse(array_keys($themes)); try { - $message = 'ThemeHandler::enable() throws InvalidArgumentException upon enabling a non-existing theme.'; - $this->themeHandler()->enable(array($name)); + $message = 'ThemeHandler::install() throws InvalidArgumentException upon installing a non-existing theme.'; + $this->themeHandler()->install(array($name)); $this->fail($message); } catch (\InvalidArgumentException $e) { @@ -127,14 +125,14 @@ function testEnableNonExisting() { } /** - * Tests enabling a theme with a too long name. + * Tests installing a theme with a too long name. */ - function testEnableNameTooLong() { + function testInstallNameTooLong() { $name = 'test_theme_having_veery_long_name_which_is_too_long'; try { - $message = 'ThemeHandler::enable() throws ExtensionNameLengthException upon enabling a theme with a too long name.'; - $this->themeHandler()->enable(array($name)); + $message = 'ThemeHandler::install() throws ExtensionNameLengthException upon installing a theme with a too long name.'; + $this->themeHandler()->install(array($name)); $this->fail($message); } catch (ExtensionNameLengthException $e) { @@ -143,79 +141,12 @@ function testEnableNameTooLong() { } /** - * Tests disabling a theme. + * Tests uninstalling the default theme. */ - function testDisable() { - $name = 'test_basetheme'; - $this->themeHandler()->enable(array($name)); - - // Prime the relevant drupal_static()s. - $this->assertEqual(array_keys(system_list('theme')), array($name)); - $this->assertIdentical(theme_get_setting('features.favicon', $name), FALSE); - - $this->themeHandler()->disable(array($name)); - - $this->assertIdentical($this->extensionConfig()->get('theme'), array()); - $this->assertIdentical($this->extensionConfig()->get("disabled.theme.$name"), 0); - - $this->assertFalse(array_keys($this->themeHandler()->listInfo())); - $this->assertFalse(array_keys(system_list('theme'))); - - // Verify that test_basetheme.settings no longer applies, even though the - // configuration still exists. - $this->assertIdentical(theme_get_setting('features.favicon', $name), TRUE); - $this->assertNull(theme_get_setting('base', $name)); - $this->assertNull(theme_get_setting('override', $name)); - - // The theme is not uninstalled, so its configuration must still exist. - $this->assertTrue($this->config("$name.settings")->get()); - } - - /** - * Tests disabling and enabling a theme. - * - * Verifies that - * - themes can be re-enabled - * - default configuration is not re-imported upon re-enabling an already - * installed theme. - */ - function testDisableEnable() { - $name = 'test_basetheme'; - - $this->themeHandler()->enable(array($name)); - $this->themeHandler()->disable(array($name)); - - $this->assertIdentical($this->config("$name.settings")->get('base'), 'only'); - $this->assertIdentical($this->config('core.date_format.fancy')->get('label'), 'Fancy date'); - - // Default configuration never overwrites custom configuration, so just - // changing values in existing configuration will cause ConfigInstaller to - // simply skip those files. To ensure that no default configuration is - // re-imported, the custom configuration has to be deleted. - $this->configStorage()->delete("$name.settings"); - $this->configStorage()->delete('core.date_format.fancy'); - // Reflect direct storage operations in ConfigFactory. - $this->container->get('config.factory')->reset(); - - $this->themeHandler()->enable(array($name)); - - $themes = $this->themeHandler()->listInfo(); - $this->assertTrue(isset($themes[$name])); - $this->assertEqual($themes[$name]->getName(), $name); - - $this->assertEqual(array_keys(system_list('theme')), array_keys($themes)); - - $this->assertFalse($this->config("$name.settings")->get()); - $this->assertNull($this->config('core.date_format.fancy')->get('label')); - } - - /** - * Tests disabling the default theme. - */ - function testDisableDefault() { + function testUninstallDefault() { $name = 'stark'; $other_name = 'bartik'; - $this->themeHandler()->enable(array($name, $other_name)); + $this->themeHandler()->install(array($name, $other_name)); $this->themeHandler()->setDefault($name); $themes = $this->themeHandler()->listInfo(); @@ -223,8 +154,8 @@ function testDisableDefault() { $this->assertTrue(isset($themes[$other_name])); try { - $message = 'ThemeHandler::disable() throws InvalidArgumentException upon disabling default theme.'; - $this->themeHandler()->disable(array($name)); + $message = 'ThemeHandler::uninstall() throws InvalidArgumentException upon disabling default theme.'; + $this->themeHandler()->uninstall(array($name)); $this->fail($message); } catch (\InvalidArgumentException $e) { @@ -237,12 +168,12 @@ function testDisableDefault() { } /** - * Tests disabling the admin theme. + * Tests uninstalling the admin theme. */ - function testDisableAdmin() { + function testUninstallAdmin() { $name = 'stark'; $other_name = 'bartik'; - $this->themeHandler()->enable(array($name, $other_name)); + $this->themeHandler()->install(array($name, $other_name)); $this->config('system.theme')->set('admin', $name)->save(); $themes = $this->themeHandler()->listInfo(); @@ -250,8 +181,8 @@ function testDisableAdmin() { $this->assertTrue(isset($themes[$other_name])); try { - $message = 'ThemeHandler::disable() throws InvalidArgumentException upon disabling admin theme.'; - $this->themeHandler()->disable(array($name)); + $message = 'ThemeHandler::uninstall() throws InvalidArgumentException upon disabling admin theme.'; + $this->themeHandler()->uninstall(array($name)); $this->fail($message); } catch (\InvalidArgumentException $e) { @@ -264,14 +195,14 @@ function testDisableAdmin() { } /** - * Tests disabling a sub-theme. + * Tests uninstalling a sub-theme. */ - function testDisableSubTheme() { + function testUninstallSubTheme() { $name = 'test_subtheme'; $base_name = 'test_basetheme'; - $this->themeHandler()->enable(array($name)); - $this->themeHandler()->disable(array($name)); + $this->themeHandler()->install(array($name)); + $this->themeHandler()->uninstall(array($name)); $themes = $this->themeHandler()->listInfo(); $this->assertFalse(isset($themes[$name])); @@ -279,17 +210,17 @@ function testDisableSubTheme() { } /** - * Tests disabling a base theme before its sub-theme. + * Tests uninstalling a base theme before its sub-theme. */ - function testDisableBaseBeforeSubTheme() { + function testUninstallBaseBeforeSubTheme() { $name = 'test_basetheme'; $sub_name = 'test_subtheme'; - $this->themeHandler()->enable(array($sub_name)); + $this->themeHandler()->install(array($sub_name)); try { - $message = 'ThemeHandler::disable() throws InvalidArgumentException upon disabling base theme before sub theme.'; - $this->themeHandler()->disable(array($name)); + $message = 'ThemeHandler::install() throws InvalidArgumentException upon uninstalling base theme before sub theme.'; + $this->themeHandler()->uninstall(array($name)); $this->fail($message); } catch (\InvalidArgumentException $e) { @@ -300,8 +231,8 @@ function testDisableBaseBeforeSubTheme() { $this->assertTrue(isset($themes[$name])); $this->assertTrue(isset($themes[$sub_name])); - // Verify that disabling both at the same time works. - $this->themeHandler()->disable(array($name, $sub_name)); + // Verify that uninstalling both at the same time works. + $this->themeHandler()->uninstall(array($name, $sub_name)); $themes = $this->themeHandler()->listInfo(); $this->assertFalse(isset($themes[$name])); @@ -309,17 +240,17 @@ function testDisableBaseBeforeSubTheme() { } /** - * Tests disabling a non-existing theme. + * Tests uninstalling a non-existing theme. */ - function testDisableNonExisting() { + function testUninstallNonExisting() { $name = 'non_existing_theme'; $themes = $this->themeHandler()->listInfo(); $this->assertFalse(array_keys($themes)); try { - $message = 'ThemeHandler::disable() throws InvalidArgumentException upon disabling a non-existing theme.'; - $this->themeHandler()->disable(array($name)); + $message = 'ThemeHandler::uninstall() throws InvalidArgumentException upon uninstalling a non-existing theme.'; + $this->themeHandler()->uninstall(array($name)); $this->fail($message); } catch (\InvalidArgumentException $e) { @@ -331,6 +262,47 @@ function testDisableNonExisting() { } /** + * Tests uninstalling a theme. + */ + function testUninstall() { + $name = 'test_basetheme'; + + $this->themeHandler()->install(array($name)); + $this->assertTrue($this->config("$name.settings")->get()); + + $this->themeHandler()->uninstall(array($name)); + + $this->assertFalse(array_keys($this->themeHandler()->listInfo())); + $this->assertFalse(array_keys(system_list('theme'))); + + $this->assertFalse($this->config("$name.settings")->get()); + + // Ensure that the uninstalled theme can be installed again. + $this->themeHandler()->install(array($name)); + $themes = $this->themeHandler()->listInfo(); + $this->assertTrue(isset($themes[$name])); + $this->assertEqual($themes[$name]->getName(), $name); + $this->assertEqual(array_keys(system_list('theme')), array_keys($themes)); + $this->assertTrue($this->config("$name.settings")->get()); + } + + /** + * Tests uninstalling a theme that is not installed. + */ + function testUninstallNotInstalled() { + $name = 'test_basetheme'; + + try { + $message = 'ThemeHandler::uninstall() throws InvalidArgumentException upon uninstalling a theme that is not installed.'; + $this->themeHandler()->uninstall(array($name)); + $this->fail($message); + } + catch (\InvalidArgumentException $e) { + $this->pass(get_class($e) . ': ' . $e->getMessage()); + } + } + + /** * Tests that theme info can be altered by a module. * * @see module_test_system_info_alter() @@ -340,7 +312,7 @@ function testThemeInfoAlter() { $this->container->get('state')->set('module_test.hook_system_info_alter', TRUE); $module_handler = $this->container->get('module_handler'); - $this->themeHandler()->enable(array($name)); + $this->themeHandler()->install(array($name)); $themes = $this->themeHandler()->listInfo(); $this->assertFalse(isset($themes[$name]->info['regions']['test_region'])); diff --git a/core/modules/system/src/Tests/Menu/MenuRouterTest.php b/core/modules/system/src/Tests/Menu/MenuRouterTest.php index c49e3fd..3ad879c 100644 --- a/core/modules/system/src/Tests/Menu/MenuRouterTest.php +++ b/core/modules/system/src/Tests/Menu/MenuRouterTest.php @@ -242,12 +242,12 @@ public function testThemeIntegration() { $this->admin_theme = 'seven'; $theme_handler = $this->container->get('theme_handler'); - $theme_handler->enable(array($this->default_theme, $this->admin_theme)); + $theme_handler->install(array($this->default_theme, $this->admin_theme)); $this->container->get('config.factory')->get('system.theme') ->set('default', $this->default_theme) ->set('admin', $this->admin_theme) ->save(); - $theme_handler->disable(array('stark')); + $theme_handler->uninstall(array('stark')); $this->doTestThemeCallbackMaintenanceMode(); @@ -294,20 +294,20 @@ protected function doTestThemeCallbackMaintenanceMode() { * Test the theme negotiation when it is set to use an optional theme. */ protected function doTestThemeCallbackOptionalTheme() { - // Request a theme that is not enabled. + // Request a theme that is not installed. $this->drupalGet('menu-test/theme-callback/use-stark-theme'); - $this->assertText('Active theme: bartik. Actual theme: bartik.', 'The theme negotiation system falls back on the default theme when a theme that is not enabled is requested.'); + $this->assertText('Active theme: bartik. Actual theme: bartik.', 'The theme negotiation system falls back on the default theme when a theme that is not installed is requested.'); $this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page."); - // Now enable the theme and request it again. + // Now install the theme and request it again. $theme_handler = $this->container->get('theme_handler'); - $theme_handler->enable(array('stark')); + $theme_handler->install(array('stark')); $this->drupalGet('menu-test/theme-callback/use-stark-theme'); - $this->assertText('Active theme: stark. Actual theme: stark.', 'The theme negotiation system uses an optional theme once it has been enabled.'); + $this->assertText('Active theme: stark. Actual theme: stark.', 'The theme negotiation system uses an optional theme once it has been installed.'); $this->assertRaw('stark/css/layout.css', "The optional theme's CSS appears on the page."); - $theme_handler->disable(array('stark')); + $theme_handler->uninstall(array('stark')); } /** diff --git a/core/modules/system/src/Tests/System/ThemeTest.php b/core/modules/system/src/Tests/System/ThemeTest.php index 6912afb..80a3c43 100644 --- a/core/modules/system/src/Tests/System/ThemeTest.php +++ b/core/modules/system/src/Tests/System/ThemeTest.php @@ -41,7 +41,7 @@ protected function setUp() { function testThemeSettings() { // Ensure invalid theme settings form URLs return a proper 404. $this->drupalGet('admin/appearance/settings/bartik'); - $this->assertResponse(404, 'The theme settings form URL for a disabled theme could not be found.'); + $this->assertResponse(404, 'The theme settings form URL for a uninstalled theme could not be found.'); $this->drupalGet('admin/appearance/settings/' . $this->randomMachineName()); $this->assertResponse(404, 'The theme settings form URL for a non-existent theme could not be found.'); @@ -179,9 +179,9 @@ function testThemeSettings() { * Test the administration theme functionality. */ function testAdministrationTheme() { - $this->container->get('theme_handler')->enable(array('seven')); + $this->container->get('theme_handler')->install(array('seven')); - // Enable an administration theme and show it on the node admin pages. + // Install an administration theme and show it on the node admin pages. $edit = array( 'admin_theme' => 'seven', 'use_admin_theme' => TRUE, @@ -238,8 +238,8 @@ function testAdministrationTheme() { * Test switching the default theme. */ function testSwitchDefaultTheme() { - // Enable Bartik and set it as the default theme. - theme_enable(array('bartik')); + // Install Bartik and set it as the default theme. + \Drupal::service('theme_handler')->install(array('bartik')); $this->drupalGet('admin/appearance'); $this->clickLink(t('Set as default')); $this->assertEqual(\Drupal::config('system.theme')->get('default'), 'bartik'); @@ -257,7 +257,7 @@ function testSwitchDefaultTheme() { } /** - * Test that themes can't be enabled when the base theme or engine is missing. + * Test themes can't be installed when the base theme or engine is missing. */ function testInvalidTheme() { // theme_page_test_system_info_alter() un-hides all hidden themes. diff --git a/core/modules/system/src/Tests/Theme/EnginePhpTemplateTest.php b/core/modules/system/src/Tests/Theme/EnginePhpTemplateTest.php index 4108d61..8cbde63 100644 --- a/core/modules/system/src/Tests/Theme/EnginePhpTemplateTest.php +++ b/core/modules/system/src/Tests/Theme/EnginePhpTemplateTest.php @@ -25,7 +25,7 @@ class EnginePhpTemplateTest extends WebTestBase { protected function setUp() { parent::setUp(); - theme_enable(array('test_theme_phptemplate')); + \Drupal::service('theme_handler')->install(array('test_theme_phptemplate')); } /** diff --git a/core/modules/system/src/Tests/Theme/EngineTwigTest.php b/core/modules/system/src/Tests/Theme/EngineTwigTest.php index c03f16b..13f947e 100644 --- a/core/modules/system/src/Tests/Theme/EngineTwigTest.php +++ b/core/modules/system/src/Tests/Theme/EngineTwigTest.php @@ -25,7 +25,7 @@ class EngineTwigTest extends WebTestBase { protected function setUp() { parent::setUp(); - theme_enable(array('test_theme')); + \Drupal::service('theme_handler')->install(array('test_theme')); } /** diff --git a/core/modules/system/src/Tests/Theme/EntityFilteringThemeTest.php b/core/modules/system/src/Tests/Theme/EntityFilteringThemeTest.php index 26aa7ec..8454fe9 100644 --- a/core/modules/system/src/Tests/Theme/EntityFilteringThemeTest.php +++ b/core/modules/system/src/Tests/Theme/EntityFilteringThemeTest.php @@ -78,10 +78,10 @@ class EntityFilteringThemeTest extends WebTestBase { protected function setUp() { parent::setUp(); - // Enable all available non-testing themes. + // Install all available non-testing themes. $listing = new ExtensionDiscovery(); $this->themes = $listing->scan('theme', FALSE); - theme_enable(array_keys($this->themes)); + \Drupal::service('theme_handler')->install(array_keys($this->themes)); // Create a test user. $this->user = $this->drupalCreateUser(array('access content', 'access user profiles')); diff --git a/core/modules/system/src/Tests/Theme/ThemeInfoTest.php b/core/modules/system/src/Tests/Theme/ThemeInfoTest.php index 7848ef3..f35ef89 100644 --- a/core/modules/system/src/Tests/Theme/ThemeInfoTest.php +++ b/core/modules/system/src/Tests/Theme/ThemeInfoTest.php @@ -59,7 +59,7 @@ protected function setUp() { * Tests stylesheets-override and stylesheets-remove. */ function testStylesheets() { - $this->themeHandler->enable(array('test_basetheme', 'test_subtheme')); + $this->themeHandler->install(array('test_basetheme', 'test_subtheme')); \Drupal::config('system.theme') ->set('default', 'test_subtheme') ->save(); @@ -92,7 +92,7 @@ function testStylesheets() { * Tests that changes to the info file are picked up. */ public function testChanges() { - $this->themeHandler->enable(array('test_theme')); + $this->themeHandler->install(array('test_theme')); $this->themeHandler->setDefault('test_theme'); $this->themeManager->resetActiveTheme(); diff --git a/core/modules/system/src/Tests/Theme/ThemeSettingsTest.php b/core/modules/system/src/Tests/Theme/ThemeSettingsTest.php index 698b66d..9275922 100644 --- a/core/modules/system/src/Tests/Theme/ThemeSettingsTest.php +++ b/core/modules/system/src/Tests/Theme/ThemeSettingsTest.php @@ -50,7 +50,7 @@ function testDefaultConfig() { $name = 'test_basetheme'; $path = $this->availableThemes[$name]->getPath(); $this->assertTrue(file_exists("$path/" . InstallStorage::CONFIG_INSTALL_DIRECTORY . "/$name.settings.yml")); - $this->container->get('theme_handler')->enable(array($name)); + $this->container->get('theme_handler')->install(array($name)); $this->assertIdentical(theme_get_setting('base', $name), 'only'); } @@ -61,7 +61,7 @@ function testNoDefaultConfig() { $name = 'stark'; $path = $this->availableThemes[$name]->getPath(); $this->assertFalse(file_exists("$path/" . InstallStorage::CONFIG_INSTALL_DIRECTORY . "/$name.settings.yml")); - $this->container->get('theme_handler')->enable(array($name)); + $this->container->get('theme_handler')->install(array($name)); $this->assertNotNull(theme_get_setting('features.favicon', $name)); } diff --git a/core/modules/system/src/Tests/Theme/ThemeSuggestionsAlterTest.php b/core/modules/system/src/Tests/Theme/ThemeSuggestionsAlterTest.php index 54fdfce..6bf00f4 100644 --- a/core/modules/system/src/Tests/Theme/ThemeSuggestionsAlterTest.php +++ b/core/modules/system/src/Tests/Theme/ThemeSuggestionsAlterTest.php @@ -26,7 +26,7 @@ class ThemeSuggestionsAlterTest extends WebTestBase { protected function setUp() { parent::setUp(); - theme_enable(array('test_theme')); + \Drupal::service('theme_handler')->install(array('test_theme')); } /** @@ -36,7 +36,7 @@ function testTemplateSuggestions() { $this->drupalGet('theme-test/suggestion-provided'); $this->assertText('Template for testing suggestions provided by the module declaring the theme hook.'); - // Enable test_theme, it contains a template suggested by theme_test.module + // Install test_theme, it contains a template suggested by theme_test.module // in theme_test_theme_suggestions_theme_test_suggestion_provided(). \Drupal::config('system.theme') ->set('default', 'test_theme') @@ -53,7 +53,7 @@ function testGeneralSuggestionsAlter() { $this->drupalGet('theme-test/general-suggestion-alter'); $this->assertText('Original template for testing hook_theme_suggestions_alter().'); - // Enable test_theme and test that themes can alter template suggestions. + // Install test_theme and test that themes can alter template suggestions. \Drupal::config('system.theme') ->set('default', 'test_theme') ->save(); @@ -75,7 +75,7 @@ function testTemplateSuggestionsAlter() { $this->drupalGet('theme-test/suggestion-alter'); $this->assertText('Original template for testing hook_theme_suggestions_HOOK_alter().'); - // Enable test_theme and test that themes can alter template suggestions. + // Install test_theme and test that themes can alter template suggestions. \Drupal::config('system.theme') ->set('default', 'test_theme') ->save(); @@ -122,7 +122,7 @@ function testThemeFunctionSuggestionsAlter() { $this->drupalGet('theme-test/function-suggestion-alter'); $this->assertText('Original theme function.'); - // Enable test_theme and test that themes can alter theme suggestions. + // Install test_theme and test that themes can alter theme suggestions. \Drupal::config('system.theme') ->set('default', 'test_theme') ->save(); @@ -163,7 +163,7 @@ public function testSuggestionsAlterInclude() { * hook_theme_suggestions_HOOK_alter() within an extension (module or theme). */ function testExecutionOrder() { - // Enable our test theme and module. + // Install our test theme and module. \Drupal::config('system.theme') ->set('default', 'test_theme') ->save(); diff --git a/core/modules/system/src/Tests/Theme/ThemeTest.php b/core/modules/system/src/Tests/Theme/ThemeTest.php index 80d21d5..718d920 100644 --- a/core/modules/system/src/Tests/Theme/ThemeTest.php +++ b/core/modules/system/src/Tests/Theme/ThemeTest.php @@ -27,7 +27,7 @@ class ThemeTest extends WebTestBase { protected function setUp() { parent::setUp(); - theme_enable(array('test_theme')); + \Drupal::service('theme_handler')->install(array('test_theme')); } /** @@ -199,11 +199,12 @@ function testFunctionOverride() { */ function testListThemes() { $theme_handler = $this->container->get('theme_handler'); - $theme_handler->enable(array('test_subtheme')); + $theme_handler->install(array('test_subtheme')); $themes = $theme_handler->listInfo(); - // Check if drupal_theme_access() retrieves enabled themes properly from list_themes(). - $this->assertTrue(drupal_theme_access('test_theme'), 'Enabled theme detected'); + // Check if drupal_theme_access() retrieves installed themes properly from + // list_themes(). + $this->assertTrue(drupal_theme_access('test_theme'), 'Installed theme detected'); // Check for base theme and subtheme lists. $base_theme_list = array('test_basetheme' => 'Theme test base theme'); @@ -221,7 +222,7 @@ function testListThemes() { * Test the theme_get_setting() function. */ function testThemeGetSetting() { - $this->container->get('theme_handler')->enable(array('test_subtheme')); + $this->container->get('theme_handler')->install(array('test_subtheme')); \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('test_theme')); $this->assertIdentical(theme_get_setting('theme_test_setting'), 'default value', 'theme_get_setting() uses the default theme automatically.'); $this->assertNotEqual(theme_get_setting('subtheme_override', 'test_basetheme'), theme_get_setting('subtheme_override', 'test_subtheme'), 'Base theme\'s default settings values can be overridden by subtheme.'); diff --git a/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php b/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php index 102f542..d5765a0 100644 --- a/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php +++ b/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php @@ -28,7 +28,7 @@ class TwigDebugMarkupTest extends WebTestBase { */ function testTwigDebugMarkup() { $extension = twig_extension(); - theme_enable(array('test_theme')); + \Drupal::service('theme_handler')->install(array('test_theme')); \Drupal::config('system.theme')->set('default', 'test_theme')->save(); $this->drupalCreateContentType(array('type' => 'page')); // Enable debug, rebuild the service container, and clear all caches. diff --git a/core/modules/system/src/Tests/Theme/TwigExtensionTest.php b/core/modules/system/src/Tests/Theme/TwigExtensionTest.php index 05c19d3..66ebf47 100644 --- a/core/modules/system/src/Tests/Theme/TwigExtensionTest.php +++ b/core/modules/system/src/Tests/Theme/TwigExtensionTest.php @@ -25,7 +25,7 @@ class TwigExtensionTest extends WebTestBase { protected function setUp() { parent::setUp(); - theme_enable(array('test_theme')); + \Drupal::service('theme_handler')->install(array('test_theme')); } /** diff --git a/core/modules/system/src/Tests/Theme/TwigNamespaceTest.php b/core/modules/system/src/Tests/Theme/TwigNamespaceTest.php index 499de80..2b759e4 100644 --- a/core/modules/system/src/Tests/Theme/TwigNamespaceTest.php +++ b/core/modules/system/src/Tests/Theme/TwigNamespaceTest.php @@ -30,7 +30,7 @@ class TwigNamespaceTest extends WebTestBase { protected function setUp() { parent::setUp(); - theme_enable(array('test_theme', 'bartik')); + \Drupal::service('theme_handler')->install(array('test_theme', 'bartik')); $this->twig = \Drupal::service('twig'); } diff --git a/core/modules/system/src/Tests/Theme/TwigSettingsTest.php b/core/modules/system/src/Tests/Theme/TwigSettingsTest.php index c7fec1d..36cc48d 100644 --- a/core/modules/system/src/Tests/Theme/TwigSettingsTest.php +++ b/core/modules/system/src/Tests/Theme/TwigSettingsTest.php @@ -82,7 +82,7 @@ function testTwigDebugOverride() { function testTwigCacheOverride() { $extension = twig_extension(); $theme_handler = $this->container->get('theme_handler'); - $theme_handler->enable(array('test_theme')); + $theme_handler->install(array('test_theme')); $theme_handler->setDefault('test_theme'); // The registry still works on theme globals, so set them here. diff --git a/core/modules/system/src/Tests/Theme/TwigTransTest.php b/core/modules/system/src/Tests/Theme/TwigTransTest.php index 98a6e9f..9983dff 100644 --- a/core/modules/system/src/Tests/Theme/TwigTransTest.php +++ b/core/modules/system/src/Tests/Theme/TwigTransTest.php @@ -54,7 +54,7 @@ protected function setUp() { parent::setUp(); // Setup test_theme. - theme_enable(array('test_theme')); + \Drupal::service('theme_handler')->install(array('test_theme')); \Drupal::config('system.theme')->set('default', 'test_theme')->save(); // Create and log in as admin. diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index c2f590f..2c205df 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -1396,6 +1396,29 @@ function hook_module_preuninstall($module) { } /** + * Perform necessary actions when themes are installed. + * + * @param array $themes + * An array of theme names which are installed. + */ +function hook_themes_installed(array $themes) { + // Add some state entries depending on the theme. + foreach ($themes as $theme) { + \Drupal::state()->set('example.' . $theme, 'some-value'); + } +} + +/** + * Perform necessary actions when themes are uninstalled. + */ +function hook_themes_uninstalled(array $themes) { + // Remove some state entries depending on the theme. + foreach ($themes as $theme) { + \Drupal::state()->delete('example.' . $theme); + } +} + +/** * Perform necessary actions after modules are uninstalled. * * This function differs from hook_uninstall() in that it gives all other diff --git a/core/modules/system/system.module b/core/modules/system/system.module index f3b65a2..4d2ab33 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -80,7 +80,7 @@ function system_help($route_name, RouteMatchInterface $route_match) { $output .= '
' . t('Managing modules') . '
'; $output .= '
' . t('The System module allows users with the appropriate permissions to enable and disable modules on the Modules administration page. Drupal comes with a number of core modules, and each module provides a discrete set of features and may be enabled or disabled depending on the needs of the site. Many additional modules contributed by members of the Drupal community are available for download at the Drupal.org module page.', array('@modules' => url('admin/modules'), '@drupal-modules' => 'http://drupal.org/project/modules')) . '
'; $output .= '
' . t('Managing themes') . '
'; - $output .= '
' . t('The System module allows users with the appropriate permissions to enable and disable themes on the Appearance administration page. Themes determine the design and presentation of your site. Drupal comes packaged with several core themes, and additional contributed themes are available at the Drupal.org theme page.', array('@themes' => url('admin/appearance'), '@drupal-themes' => 'http://drupal.org/project/themes')) . '
'; + $output .= '
' . t('The System module allows users with the appropriate permissions to install and uninstall themes on the Appearance administration page. Themes determine the design and presentation of your site. Drupal comes packaged with several core themes, and additional contributed themes are available at the Drupal.org theme page.', array('@themes' => url('admin/appearance'), '@drupal-themes' => 'http://drupal.org/project/themes')) . '
'; $output .= '
' . t('Managing caching') . '
'; $output .= '
' . t("The System module allows users with the appropriate permissions to manage caching on the Performance settings page. Drupal has a robust caching system that allows the efficient re-use of previously-constructed web pages and web page components. Pages requested by anonymous users are stored in a compressed format; depending on your site configuration and the amount of your web traffic tied to anonymous visitors, the caching system may significantly increase the speed of your site.", array('@cache-settings' => url('admin/config/development/performance'))) . '
'; $output .= '
' . t('Performing system maintenance') . '
'; @@ -376,7 +376,7 @@ function system_stream_wrappers() { } /** - * Menu item access callback - only enabled themes can be accessed. + * Menu item access callback - only installed themes can be accessed. */ function _system_themes_access($theme) { return \Drupal::currentUser()->hasPermission('administer themes') && drupal_theme_access($theme); diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index 8034863..6df0e0c 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -253,18 +253,18 @@ system.modules_list_confirm: requirements: _permission: 'administer modules' -system.theme_disable: - path: '/admin/appearance/disable' +system.theme_uninstall: + path: '/admin/appearance/uninstall' defaults: - _controller: 'Drupal\system\Controller\ThemeController::disable' + _controller: 'Drupal\system\Controller\ThemeController::uninstall' requirements: _permission: 'administer themes' _csrf_token: 'TRUE' -system.theme_enable: - path: '/admin/appearance/enable' +system.theme_install: + path: '/admin/appearance/install' defaults: - _controller: 'Drupal\system\Controller\ThemeController::enable' + _controller: 'Drupal\system\Controller\ThemeController::install' requirements: _permission: 'administer themes' _csrf_token: 'TRUE' diff --git a/core/modules/system/templates/system-themes-page.html.twig b/core/modules/system/templates/system-themes-page.html.twig index e40545b..9d55c21 100644 --- a/core/modules/system/templates/system-themes-page.html.twig +++ b/core/modules/system/templates/system-themes-page.html.twig @@ -8,7 +8,7 @@ * - theme_groups: A list of theme groups. Each theme group contains: * - attributes: HTML attributes specific to this theme group. * - title: Title for the theme group. - * - state: State of the theme group, e.g. enabled or disabled. + * - state: State of the theme group, e.g. installed or uninstalled. * - themes: A list of themes within the theme group. Each theme contains: * - attributes: HTML attributes specific to this theme. * - screenshot: A screenshot representing the theme. diff --git a/core/modules/system/tests/modules/menu_test/src/Theme/TestThemeNegotiator.php b/core/modules/system/tests/modules/menu_test/src/Theme/TestThemeNegotiator.php index 3d3a17e..b4cdd0a 100644 --- a/core/modules/system/tests/modules/menu_test/src/Theme/TestThemeNegotiator.php +++ b/core/modules/system/tests/modules/menu_test/src/Theme/TestThemeNegotiator.php @@ -34,7 +34,7 @@ public function determineActiveTheme(RouteMatchInterface $route_match) { if ($argument == 'use-admin-theme') { return \Drupal::config('system.theme')->get('admin'); } - // Test using a theme that exists, but may or may not be enabled. + // Test using a theme that exists, but may or may not be installed. elseif ($argument == 'use-stark-theme') { return 'stark'; } diff --git a/core/modules/system/theme.api.php b/core/modules/system/theme.api.php index 089334f..70426ec 100644 --- a/core/modules/system/theme.api.php +++ b/core/modules/system/theme.api.php @@ -468,28 +468,30 @@ function hook_theme_suggestions_HOOK_alter(array &$suggestions, array $variables } /** - * Respond to themes being enabled. + * Respond to themes being installed. * * @param array $theme_list - * Array containing the names of the themes being enabled. + * Array containing the names of the themes being installed. * - * @see theme_enable() + * @see \Drupal\Core\Extension\ThemeHandler::install() */ -function hook_themes_enabled($theme_list) { +function hook_themes_installed($theme_list) { foreach ($theme_list as $theme) { block_theme_initialize($theme); } } /** - * Respond to themes being disabled. + * Respond to themes being uninstalled. * * @param array $theme_list - * Array containing the names of the themes being disabled. + * Array containing the names of the themes being uninstalled. * - * @see theme_disable() + * @see \Drupal\Core\Extension\ThemeHandler::uninstall() */ -function hook_themes_disabled($theme_list) { - // Clear all update module caches. - update_storage_clear(); +function hook_themes_uninstalled(array $themes) { + // Remove some state entries depending on the theme. + foreach ($themes as $theme) { + \Drupal::state()->delete('example.' . $theme); + } } diff --git a/core/modules/taxonomy/src/Tests/ThemeTest.php b/core/modules/taxonomy/src/Tests/ThemeTest.php index 4acef7e..9ababed 100644 --- a/core/modules/taxonomy/src/Tests/ThemeTest.php +++ b/core/modules/taxonomy/src/Tests/ThemeTest.php @@ -19,7 +19,7 @@ protected function setUp() { // Make sure we are using distinct default and administrative themes for // the duration of these tests. - theme_enable(array('bartik', 'seven')); + \Drupal::service('theme_handler')->install(array('bartik', 'seven')); \Drupal::config('system.theme') ->set('default', 'bartik') ->set('admin', 'seven') diff --git a/core/modules/tour/src/Tests/TourTestBasic.php b/core/modules/tour/src/Tests/TourTestBasic.php index 49dafdc..08680e0 100644 --- a/core/modules/tour/src/Tests/TourTestBasic.php +++ b/core/modules/tour/src/Tests/TourTestBasic.php @@ -49,7 +49,7 @@ protected function setUp() { // Make sure we are using distinct default and administrative themes for // the duration of these tests. - $this->container->get('theme_handler')->enable(array('bartik', 'seven')); + $this->container->get('theme_handler')->install(array('bartik', 'seven')); $this->container->get('config.factory') ->get('system.theme') ->set('default', 'bartik') diff --git a/core/modules/update/src/Tests/UpdateContribTest.php b/core/modules/update/src/Tests/UpdateContribTest.php index 0e547ef..622d448 100644 --- a/core/modules/update/src/Tests/UpdateContribTest.php +++ b/core/modules/update/src/Tests/UpdateContribTest.php @@ -162,8 +162,10 @@ function testUpdateContribOrder() { * Tests that subthemes are notified about security updates for base themes. */ function testUpdateBaseThemeSecurityUpdate() { - // Only enable the subtheme, not the base theme. - theme_enable(array('update_test_subtheme')); + // @todo https://www.drupal.org/node/2338175 base themes have to be + // installed. + // Only install the subtheme, not the base theme. + \Drupal::service('theme_handler')->install(array('update_test_subtheme')); // Define the initial state for core and the subtheme. $system_info = array( @@ -197,6 +199,9 @@ function testUpdateBaseThemeSecurityUpdate() { /** * Tests that disabled themes are only shown when desired. + * + * @todo https://www.drupal.org/node/2338175 extensions can not be hidden and + * base themes have to be installed. */ function testUpdateShowDisabledThemes() { $update_settings = \Drupal::config('update.settings'); @@ -244,7 +249,8 @@ function testUpdateShowDisabledThemes() { foreach (array(TRUE, FALSE) as $check_disabled) { $update_settings->set('check.disabled_extensions', $check_disabled)->save(); $this->refreshUpdateStatus($xml_mapping); - // In neither case should we see the "Themes" heading for enabled themes. + // In neither case should we see the "Themes" heading for installed + // themes. $this->assertNoText(t('Themes')); if ($check_disabled) { $this->assertText(t('Disabled themes')); @@ -265,8 +271,8 @@ function testUpdateShowDisabledThemes() { function testUpdateHiddenBaseTheme() { module_load_include('compare.inc', 'update'); - // Enable the subtheme. - theme_enable(array('update_test_subtheme')); + // Install the subtheme. + \Drupal::service('theme_handler')->install(array('update_test_subtheme')); // Add a project and initial state for base theme and subtheme. $system_info = array( diff --git a/core/modules/update/update.module b/core/modules/update/update.module index 6529a48..4201e5d 100644 --- a/core/modules/update/update.module +++ b/core/modules/update/update.module @@ -231,21 +231,21 @@ function update_cron() { } /** - * Implements hook_themes_enabled(). + * Implements hook_themes_installed(). * - * If themes are enabled, we invalidate the information of available updates. + * If themes are installed, we invalidate the information of available updates. */ -function update_themes_enabled($themes) { +function update_themes_installed($themes) { // Clear all update module data. update_storage_clear(); } /** - * Implements hook_themes_disabled(). + * Implements hook_themes_uninstalled(). * - * If themes are disabled, we invalidate the information of available updates. + * If themes are uninstalled, we invalidate the information of available updates. */ -function update_themes_disabled($themes) { +function update_themes_uninstalled($themes) { // Clear all update module data. update_storage_clear(); } diff --git a/core/modules/views/src/Tests/ViewsThemeIntegrationTest.php b/core/modules/views/src/Tests/ViewsThemeIntegrationTest.php index a73523c..e368c84 100644 --- a/core/modules/views/src/Tests/ViewsThemeIntegrationTest.php +++ b/core/modules/views/src/Tests/ViewsThemeIntegrationTest.php @@ -50,7 +50,7 @@ protected function setUp() { */ public function testThemedViewPage() { - \Drupal::service('theme_handler')->enable(array('test_basetheme', 'test_subtheme')); + \Drupal::service('theme_handler')->install(array('test_basetheme', 'test_subtheme')); // Make base theme default then test for hook invocations. \Drupal::config('system.theme') diff --git a/core/tests/Drupal/Tests/Core/Extension/DefaultConfigTest.php b/core/tests/Drupal/Tests/Core/Extension/DefaultConfigTest.php index b1c1c8b..a4bb8b1 100644 --- a/core/tests/Drupal/Tests/Core/Extension/DefaultConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/DefaultConfigTest.php @@ -32,9 +32,6 @@ public function testConfigIsEmpty() { $expected = array( 'module' => array(), 'theme' => array(), - 'disabled' => array( - 'theme' => array(), - ), ); $this->assertEquals($expected, $config); } diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php index 56bab8f..3d89abe 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php @@ -64,6 +64,13 @@ class ThemeHandlerTest extends UnitTestCase { protected $configInstaller; /** + * The mocked config manager. + * + * @var \Drupal\Core\Config\ConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $configManager; + + /** * The extension discovery. * * @var \Drupal\Core\Extension\ExtensionDiscovery|\PHPUnit_Framework_MockObject_MockObject @@ -101,6 +108,7 @@ protected function setUp() { $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->getMockBuilder('Drupal\Core\Routing\RouteBuilder') ->disableOriginalConstructor() ->getMock(); @@ -111,7 +119,7 @@ protected function setUp() { ->disableOriginalConstructor() ->getMock(); $logger = $this->getMock('Psr\Log\LoggerInterface'); - $this->themeHandler = new TestThemeHandler($this->configFactory, $this->moduleHandler, $this->state, $this->infoParser, $logger, $this->cssCollectionOptimizer, $this->configInstaller, $this->routeBuilder, $this->extensionDiscovery); + $this->themeHandler = new TestThemeHandler($this->configFactory, $this->moduleHandler, $this->state, $this->infoParser, $logger, $this->cssCollectionOptimizer, $this->configInstaller, $this->configManager, $this->routeBuilder, $this->extensionDiscovery); $cache_backend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); $this->getContainerWithCacheBins($cache_backend);