8

I am trying to build an install profile and I want to have my custom theme enabled and set by default after the installation.

Adding in MYPROFILE.info.yml...

theme:
  - my_theme

...is not enough. This only installs it, but it is not set as the default theme.

I guess I have to do something else in the MYPROFILE.install file in

function MYPROFILE_install() {
  // how to set as default my custom theme
}

Thank you

11

Looking at ThemeController::setDefaultTheme (the request handler for the /admin/appearance/default route), this should do the trick:

\Drupal::configFactory()
  ->getEditable('system.theme')
  ->set('default', 'machine_name')
  ->save();
  • For this to work, theme must be already enabled. Still don't know how to enable it programmatically. – dxvargas Feb 11 '17 at 12:12
  • 3
    @hiphip Fortunately that's quite straightforward: \Drupal::service('theme_installer')->install(['theme_name']); – Clive Feb 11 '17 at 12:16
-2

You can create a site that has the correct default theme, and copy over the theme related config files into your profile's config directory (or all the files if it makes sense for your profile).

See https://www.drupal.org/node/2210443#config for more.

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.