Odpowiedzi:
Korzystanie z menedżera motywów to właściwy sposób uzyskiwania informacji o motywie przez Drupal 8.
\Drupal::service('theme.manager')->getActiveTheme()
Ogólną regułą w drupal 8 jest poszukiwanie usługi manager (/ handler).
** Uwaga: jak wskazał Neograph734 , \Drupal::service('theme.manager')->getActiveTheme()zwróci aktywny obiekt motywu . Jeśli chcesz uzyskać nazwę maszyny-motywu, użyj\Drupal::service('theme.manager')->getActiveTheme()->getName()
To zrobi to:
$config = \Drupal::config('system.theme');
print $config->get('default');
Zawsze możesz użyć drush do eksploracji dostępnych konfiguracji:
drush config-list
i
drush config-list system
dał mi listę:
...
system.rss
system.site
system.theme.global
system.theme
...
a następnie mogłem sprawdzić za pomocą:
drush cget system.theme.global
i
drush cget system.theme
aby w końcu dowiedzieć się, że posiada defaultwłaściwość, o którą prosiłeś.
getActiveTheme()funkcja zwróci dokładnie to samo: $this->configFactory->get('system.theme')->get('default')
administration themeUżyj:
$activeThemeName = \Drupal::service('theme.manager')->getActiveTheme();
theme used in frontnie był
admistartion themeużywany:
$defaultThemeName = \Drupal::config('system.theme')->get('default');
getName(). Aby uzyskać nazwę motywu, należy użyć\Drupal::service('theme.manager')->getActiveTheme()->getName();