Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

Prior to Drupal 8 themes did not have an installation status. This meant that

  1. all themes were loaded at all times; and
  2. the configuration settings of a theme were not maintained and uninstalled.

In Drupal 8, themes have an installation status now, which means:

  1. A theme has to be installed and enabled in order to use it.
  2. When a sub-theme is installed, then its base theme(s) are installed, too.
  3. Only installed and enabled themes can be used and configured as default theme and admin theme.
  4. Installing a theme imports its default configuration.
  5. 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

  1. 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.
  2. String translations were re-imported whenever the theme was (re-)enabled.

Drupal 8

  1. The default configuration of a theme is only imported once when the theme is initially installed/enabled.
  2. String translations are only imported once when the theme is initially installed/enabled.

Base theme developers

Drupal 7

  1. A base theme and its functionality was available and usable at all times, regardless of whether installed/enabled or not.

Drupal 8

  1. A base theme and its functionality is only available and usable after it has been installed/enabled.

Installation profile authors

Drupal 7

  1. The Stark theme was always installed and enabled by default, and had to be manually disabled in hook_install():
      theme_disable(array('stark'));
    
  2. The actual default and admin themes had to be manually enabled in hook_install():
      theme_enable(array('bartik', 'seven'));
    
  3. 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

  1. Stark is no longer installed by default.

  2. 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.

  3. 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

  1. All functional tests should verify the default theme output of modules only, which is the default now.

  2. 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();
    
Impacts: 
Site builders, administrators, editors
Module developers
Themers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

KarenS’s picture

This is deprecated:

$this->container->get('theme_handler')->enable(array('bartik', 'seven'));
  $this->container->get('config.factory')
    ->get('system.theme')
    ->set('default', 'bartik')
    ->set('admin', 'seven')
    ->save();

I think it should be:

$this->container->get('theme_installer')->install(array('bartik', 'seven'));
  $this->container->get('config.factory')
    ->getEditable('system.theme')
    ->set('default', 'bartik')
    ->set('admin', 'seven')
    ->save();

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.

DamienMcKenna’s picture

A single line to find the current default theme:

\Drupal::service('config.factory')->get('system.theme')->get('default');

--
Damien McKenna | Mediacurrent