/** * {@inheritdoc} */ 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->getSettingPlugins() 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); }
/** * {@inheritdoc} */ public function save($has_trusted_data = FALSE) { parent::save($has_trusted_data); $this->theme->getCache('settings')->deleteAll(); return $this; }