I was building a block for which I have to provide bubblable metadata. The data in this block is depending on individual theme configurations as well as the global theme settings.

So I tried the following:

$config = \Drupal::config('system.theme.global');

$config2 = \Drupal::config('bartik.settings');

This however obviously does not work if the theme is not set to bartik. I have been attempting to find the theme configuration in \Drupal::theme()->getActiveTheme(), but that does not provide this data.

I suppose I could try $config = \Drupal::theme()->getActiveTheme()->getName() . '.settings';, but I'd like to learn if there are better ways.

How to get the configuration (or config name) of the current active theme?


It seems this is actually the recommended way. It is used in theme_get_settings() as well:

$theme = \Drupal::theme()->getActiveTheme()->getName();
  if ($theme_settings = \Drupal::config($theme . '.settings')->get()) {
| improve this answer | |

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.