You are here

public function ThemeSettings::getThemeConfig in Express 8

Retrieves a specific theme's stored config settings.

Parameters

\Drupal\bootstrap\Theme $theme: A theme object.

bool $active_theme: Flag indicating whether or not $theme is the active theme.

Return value

array A array diff of overridden config theme settings.

1 call to ThemeSettings::getThemeConfig()
ThemeSettings::__construct in themes/contrib/bootstrap/src/ThemeSettings.php
Constructs a configuration object.

File

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

Class

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

Namespace

Drupal\bootstrap

Code

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 schemas if not the active theme.
      if (!$active_theme) {
        unset($theme_settings['schemas']);
      }
      $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;
}