Skip to content

Instantly share code, notes, and snippets.

View augustofagioli's full-sized avatar
🎯
writing

Augusto augustofagioli

🎯
writing
View GitHub Profile
@andriyun
andriyun / drupal8-change-active-theme-programmatically.php
Last active November 22, 2022 19:56
Drupal 8 switch active theme programmatically
<?php
/**
* See original implementation http://cgit.drupalcode.org/mailsystem/tree/src/MailsystemManager.php#n60
*/
// Switch the theme to the configured mail theme.
$theme_manager = \Drupal::service('theme.manager');
$mail_theme = '[your theme name]';
$current_active_theme = $theme_manager->getActiveTheme();
if ($mail_theme && $mail_theme != $current_active_theme->getName()) {
$theme_initialization = \Drupal::service('theme.initialization');