Question

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

Was it helpful?

Solution

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();

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top