You are here

public function ThemeHandler::setDefault in Drupal 8

Sets a new default theme.

Parameters

string $theme: The new default theme.

Return value

$this

Overrides ThemeHandlerInterface::setDefault

Deprecated

in drupal:8.2.0 and is removed from drupal:9.0.0. Use the configuration system to edit the system.theme config directly.

See also

https://www.drupal.org/node/3082630

File

core/lib/Drupal/Core/Extension/ThemeHandler.php, line 68

Class

ThemeHandler
Default theme handler using the config system to store installation statuses.

Namespace

Drupal\Core\Extension

Code

public function setDefault($name) {
  @trigger_error(__METHOD__ . ' is deprecated in drupal:8.2.0 and is removed from drupal:9.0.0. Use the configuration system to edit the system.theme config directly. See https://www.drupal.org/node/3082630', E_USER_DEPRECATED);
  $list = $this
    ->listInfo();
  if (!isset($list[$name])) {
    throw new UninstalledExtensionException("{$name} theme is not installed.");
  }
  $this->configFactory
    ->getEditable('system.theme')
    ->set('default', $name)
    ->save();
  return $this;
}