/**
  * Retrieves a specific theme's stored config settings.
  *
  * @param \Drupal\materialize\Theme $theme
  *   A theme object.
  * @param bool $active_theme
  *   Flag indicating whether or not $theme is the active theme.
  *
  * @return array
  *   A array diff of overridden config theme settings.
  */
 public function getThemeConfig(Theme $theme, $active_theme = FALSE)
 {
     $config = new \Drupal\Core\Theme\ThemeSettings($theme->getName());
     // Retrieve configured theme-specific settings, if any.
     try {
         if ($theme_settings = \Drupal::config($theme->getName() . '.settings')->get()) {
             // Remove the schema version if not the active theme.
             if (!$active_theme) {
                 unset($theme_settings['schema']);
             }
             $config->merge($theme_settings);
         }
     } catch (StorageException $e) {
     }
     // If the theme does not support a particular feature, override the
     // global setting and set the value to NULL.
     $info = $theme->getInfo();
     if (!empty($info['features'])) {
         foreach (_system_default_theme_features() as $feature) {
             if (!in_array($feature, $info['features'])) {
                 $config->set('features.' . $feature, NULL);
             }
         }
     }
     // Generate the path to the logo image.
     if ($config->get('features.logo')) {
         $logo_url = FALSE;
         foreach (['svg', 'png', 'jpg'] as $type) {
             if (file_exists($theme->getPath() . "/logo.{$type}")) {
                 $logo_url = file_create_url($theme->getPath() . "/logo.{$type}");
                 break;
             }
         }
         if ($config->get('logo.use_default') && $logo_url) {
             $config->set('logo.url', $logo_url);
         } elseif (($logo_path = $config->get('logo.path')) && file_exists($logo_path)) {
             $config->set('logo.url', file_create_url($logo_path));
         }
     }
     // Generate the path to the favicon.
     if ($config->get('features.favicon')) {
         $favicon_url = $theme->getPath() . '/favicon.ico';
         if ($config->get('favicon.use_default') && file_exists($favicon_url)) {
             $config->set('favicon.url', file_create_url($favicon_url));
         } elseif ($favicon_path = $config->get('favicon.path')) {
             $config->set('favicon.url', file_create_url($favicon_path));
         }
     }
     // Retrieve the config data.
     $data = $config->get();
     // Retrieve a diff of settings that override the defaults.
     $diff = DiffArray::diffAssocRecursive($data, $this->defaults);
     // Ensure core features are always present in the diff. The theme settings
     // form will not work properly otherwise.
     // @todo Just rebuild the features section of the form?
     foreach (['favicon', 'features', 'logo'] as $key) {
         $arrays = [];
         $arrays[] = isset($this->defaults[$key]) ? $this->defaults[$key] : [];
         $arrays[] = isset($data[$key]) ? $data[$key] : [];
         $diff[$key] = NestedArray::mergeDeepArray($arrays, TRUE);
     }
     return $diff;
 }
示例#2
0
 /**
  * Retrieves a specific theme's stored config settings.
  *
  * @param \Drupal\bootstrap\Theme $theme
  *   A theme object.
  * @param bool $active_theme
  *   Flag indicating whether or not $theme is the active theme.
  *
  * @return array
  *   A array diff of overridden config theme settings.
  */
 public function getThemeConfig(Theme $theme, $active_theme = FALSE)
 {
     $config = new \Drupal\Core\Theme\ThemeSettings($theme->getName());
     // Retrieve configured theme-specific settings, if any.
     try {
         if ($theme_settings = \Drupal::config($theme->getName() . '.settings')->get()) {
             // Remove the schema version if not the active theme.
             if (!$active_theme) {
                 unset($theme_settings['schema']);
             }
             $config->merge($theme_settings);
         }
     } catch (StorageException $e) {
     }
     // If the theme does not support a particular feature, override the
     // global setting and set the value to NULL.
     $info = $theme->getInfo();
     if (!empty($info['features'])) {
         foreach (_system_default_theme_features() as $feature) {
             if (!in_array($feature, $info['features'])) {
                 $config->set('features.' . $feature, NULL);
             }
         }
     }
     // Generate the path to the logo image.
     if ($config->get('logo.use_default')) {
         $config->set('logo.url', file_create_url($theme->getPath() . '/logo.svg'));
     } elseif ($logo_path = $config->get('logo.path')) {
         $config->set('logo.url', file_create_url($logo_path));
     }
     // Generate the path to the favicon.
     if ($config->get('features.favicon')) {
         $favicon_path = $config->get('favicon.path');
         if ($config->get('favicon.use_default')) {
             if (file_exists($favicon = $theme->getPath() . '/favicon.ico')) {
                 $config->set('favicon.url', file_create_url($favicon));
             } else {
                 $config->set('favicon.url', file_create_url('core/misc/favicon.ico'));
             }
         } elseif ($favicon_path) {
             $config->set('favicon.url', file_create_url($favicon_path));
         } else {
             $config->set('features.favicon', FALSE);
         }
     }
     // Return a diff of the overrides from set defaults.
     $diff = DiffArray::diffAssocRecursive($config->get(), $this->defaults);
     return $diff;
 }