Risposte:
L'utilizzo del gestore del tema è il modo Drupal 8 corretto per ottenere informazioni sul tema.
\Drupal::service('theme.manager')->getActiveTheme()
Una regola generale in drupal 8 è cercare il servizio manager (/ handler).
** Nota: come sottolineato da Neograph734 , \Drupal::service('theme.manager')->getActiveTheme()verrà restituito l' oggetto tema attivo . Se vuoi ottenere il tema nome-macchina, allora usa\Drupal::service('theme.manager')->getActiveTheme()->getName()
Questo lo farà:
$config = \Drupal::config('system.theme');
print $config->get('default');
Puoi sempre usare drush per esplorare le tue configurazioni disponibili:
drush config-list
e
drush config-list system
mi ha dato un elenco:
...
system.rss
system.site
system.theme.global
system.theme
...
e quindi ho potuto verificare con quanto segue:
drush cget system.theme.global
e
drush cget system.theme
per scoprire finalmente che possiede una defaultproprietà che era quello che hai chiesto.
getActiveTheme()funzione finirà per restituire esattamente lo stesso: $this->configFactory->get('system.theme')->get('default')
administration themeincludere il nome effettivo del tema attivo
$activeThemeName = \Drupal::service('theme.manager')->getActiveTheme();
theme used in frontnon sia
admistartion themeutilizzato:
$defaultThemeName = \Drupal::config('system.theme')->get('default');
Ho trovato via sotto in Drupal 8
$theme = \Drupal::theme()->getActiveTheme();
getName(). Quindi, per ottenere il nome del tema si dovrebbe usare\Drupal::service('theme.manager')->getActiveTheme()->getName();