You are here

public function GutenbergLibraryManager::getActiveThemeDefinitions in Gutenberg 8.2

Gets a list of the active theme's .gutenberg.yml definitions.

It also pulls in the base theme definitions.

Return value

array The theme definitions.

Overrides GutenbergLibraryManagerInterface::getActiveThemeDefinitions

1 call to GutenbergLibraryManager::getActiveThemeDefinitions()
GutenbergLibraryManager::getActiveThemeMergedDefinition in src/GutenbergLibraryManager.php
Get the active theme merged definition.

File

src/GutenbergLibraryManager.php, line 196

Class

GutenbergLibraryManager
Provides the default .gutenberg.yml library plugin manager.

Namespace

Drupal\gutenberg

Code

public function getActiveThemeDefinitions() {
  if (isset($this->activeThemeDefinitions)) {
    return $this->activeThemeDefinitions;
  }
  $cid = $this->cacheKey . ':active_themes';
  if ($cache = $this->cacheBackend
    ->get($cid)) {
    return $this->activeThemeDefinitions = $cache->data;
  }
  $theme_name = $this->themeHandler
    ->getDefault();
  $theme_definitions = [];
  try {
    $active_theme = $this->themeInitialization
      ->getActiveThemeByName($theme_name);
    $definitions = $this
      ->getDefinitionsByExtension();

    // Note: Reversing the order so that base themes are first.
    $themes = array_reverse(array_merge([
      $active_theme
        ->getName(),
    ], array_keys($active_theme
      ->getBaseThemeExtensions())));
    foreach ($themes as $theme) {
      if (isset($definitions['theme'][$theme])) {
        $theme_definitions[$theme] = $definitions['theme'][$theme];
      }
    }
  } catch (MissingThemeDependencyException $e) {
    $this->logger
      ->error($e
      ->getMessage());
  }
  $this->cacheBackend
    ->set($cid, $theme_definitions, Cache::PERMANENT, [
    'gutenberg',
  ]);
  $this->activeThemeDefinitions = $theme_definitions;
  return $this->activeThemeDefinitions;
}