Prior to Drupal 8 themes did not have an installation status. This meant that
- all themes were loaded at all times; and
- the configuration settings of a theme were not maintained and uninstalled.
In Drupal 8, themes have an installation status now, which means:
- A theme has to be installed and enabled in order to use it.
- When a sub-theme is installed, then its base theme(s) are installed, too.
- Only installed and enabled themes can be used and configured as default theme and admin theme.
- Installing a theme imports its default configuration.
- Uninstalling a theme removes all of its configuration.
By default, "no theme" is installed; i.e., the theme system generates output based on the default theme implementations in modules only (basically like the Stark theme, just without Stark). — This situation does not exist in a regular Drupal installation, because the Drupal installer always installs a theme. However, this setup can be and is actively used in e.g. tests extending KernelTestBase
(to verify the default theme output only).
The impact of this change varies by audience:
Theme authors
Drupal 7
theme_get_setting()
worked at all times. The default settings of a theme always existed; there was no process or facility to install or initialize theme settings.- String translations were re-imported whenever the theme was (re-)enabled.
Drupal 8
- The default configuration of a theme is only imported once when the theme is initially installed/enabled.
- String translations are only imported once when the theme is initially installed/enabled.
Base theme developers
Drupal 7
- A base theme and its functionality was available and usable at all times, regardless of whether installed/enabled or not.
Drupal 8
- A base theme and its functionality is only available and usable after it has been installed/enabled.
Installation profile authors
Drupal 7
- The Stark theme was always installed and enabled by default, and had to be manually disabled in
hook_install()
:
theme_disable(array('stark'));
- The actual default and admin themes had to be manually enabled in
hook_install()
:
theme_enable(array('bartik', 'seven'));
- The default and admin themes had to be manually configured in
hook_install()
:
variable_set('theme_default', 'bartik'); variable_set('admin_theme', 'seven');
Drupal 8
-
Stark is no longer installed by default.
-
An installation profile specifies the list of themes to install and enable in its
.info.yml
file:themes: - bartik - seven
If the
'themes'
property omitted, the list defaults to'stark'
.If a specified theme depends on another (base) theme, then the dependencies do not have to be specified, but are automatically installed and enabled.
-
Like any other configuration, the installation profile overrides the default
system.theme.yml
configuration file of System module by copying it into the installation profile's default config directory and adjusting the values accordingly:default: bartik admin: seven
The
system.theme
configuration defaults to:default: stark admin: ''
Test authors
Drupal 8
-
All functional tests should verify the default theme output of modules only, which is the default now.
-
To explicitly test against a particular theme, it first has to be installed and then set as default. For example:
$this->container->get('theme_handler')->enable(array('bartik', 'seven')); $this->container->get('config.factory') ->get('system.theme') ->set('default', 'bartik') ->set('admin', 'seven') ->save();
Comments
Deprecated
This is deprecated:
I think it should be:
I'm trying to use this to install a contrib theme in a test and even with this change it's not working because it can't find the test. But the original fails because the class name is not found.
Quick code to find the current default theme
A single line to find the current default theme:
--
Damien McKenna | Mediacurrent