I need to programmatically update my default theme and disable bartik on a live site. I know I need to update the config. In Drupal 7 I would have used theme_enable(), but I am not sure how to do this in Drupal 8. Below my function sets 'mycustomtheme' by default but it does not enable the theme. Thanks in advance.

  function mysite_deploy_update_8001() {
      ->set('default', 'mycustomtheme')

Use the theme installer service to enable and disable themes .

Install a list of themes:


Uninstall a list of themes:


Reference: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension%21ThemeInstaller.php/function/ThemeInstaller%3A%3Ainstall/8.2.x

Instead of writing to the config you can use the theme handler to set a default theme:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.