You are here

public function ThemeSettings::__construct in Express 8

Constructs a configuration object.

Parameters

string $name: The name of the configuration object being constructed.

\Drupal\Core\Config\StorageInterface $storage: A storage object to use for reading and writing the configuration data.

\Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher: An event dispatcher instance to use for configuration events.

\Drupal\Core\Config\TypedConfigManagerInterface $typed_config: The typed configuration manager service.

Overrides Config::__construct

File

themes/contrib/bootstrap/src/ThemeSettings.php, line 41
Contains \Drupal\bootstrap\ThemeSettings.

Class

ThemeSettings
Provides a configuration API wrapper for runtime merged theme settings.

Namespace

Drupal\bootstrap

Code

public function __construct(Theme $theme) {
  parent::__construct($theme
    ->getName() . '.settings', \Drupal::service('config.storage'), \Drupal::service('event_dispatcher'), \Drupal::service('config.typed'));
  $this->theme = $theme;

  // Retrieve cache.
  $cache = $theme
    ->getCache('settings');

  // Use cached settings.
  if ($defaults = $cache
    ->get('defaults')) {
    $this->defaults = $defaults;
    $this
      ->initWithData($cache
      ->get('data', []));
    return;
  }

  // Retrieve the global settings from configuration.
  $this->defaults = \Drupal::config('system.theme.global')
    ->get();

  // Retrieve the theme setting plugin discovery defaults (code).
  foreach ($theme
    ->getSettingPlugin() as $name => $setting) {
    $this->defaults[$name] = $setting
      ->getDefaultValue();
  }

  // Retrieve the theme ancestry.
  $ancestry = $theme
    ->getAncestry();

  // Remove the active theme from the ancestry.
  $active_theme = array_pop($ancestry);

  // Iterate and merge all ancestor theme config into the defaults.
  foreach ($ancestry as $ancestor) {
    $this->defaults = NestedArray::mergeDeepArray([
      $this->defaults,
      $this
        ->getThemeConfig($ancestor),
    ], TRUE);
  }

  // Merge the active theme config.
  $this
    ->initWithData($this
    ->getThemeConfig($active_theme, TRUE));

  // Cache the data and defaults.
  $cache
    ->set('data', $this->data);
  $cache
    ->set('defaults', $this->defaults);
}