function public function CdnAssets::getThemes

8.x-3.x CdnAssets.php public CdnAssets::getThemes()

Groups available assets by theme.

Return value

\Drupal\bootstrap\Plugin\Provider\CdnAssets[] A collection of newly created CdnAssets objects, keyed by theme name.

Class

CdnAssets
Class CdnAssets.

Namespace

Drupal\bootstrap\Plugin\Provider

Source src/Plugin/Provider/CdnAssets.php (line 186)

public function getThemes() {
  /** @var \Drupal\bootstrap\Plugin\Provider\CdnAssets[] $themes */
  $themes = [];
  foreach ($this->assets as $asset) {
    $theme = $asset->getTheme();
    if (!isset($themes[$theme])) {
      $themes[$theme] = (new static())
        ->setLabel($asset->getLabel())
        ->setLibrary($asset->getLibrary());
    }
    $themes[$theme]->append($asset);
  }

  // Sort the themes.
  uksort($themes, [$this, 'sortThemes']);

  // Post process the themes to fill in any missing assets.
  $bootstrap = isset($themes['bootstrap']) ? $themes['bootstrap'] : new static();
  foreach (array_keys($themes) as $theme) {
    // The example Bootstrap theme are just overrides, it requires the main
    // bootstrap library CSS to be loaded first.
    if ($theme === 'bootstrap_theme') {
      if ($css = $bootstrap->get('css', TRUE)) {
        $themes['bootstrap_theme']->prependAssets($css);
      }
      if ($css = $bootstrap->get('css', FALSE)) {
        $themes['bootstrap_theme']->prependAssets($css);
      }
    }

    // Populate missing JavaScript.
    if (!$themes[$theme]->get('js', TRUE)) {
      if ($js = $bootstrap->get('js', FALSE)) {
        $themes[$theme]->appendAssets($js);
      }
      if ($js = $bootstrap->get('js', TRUE)) {
        $themes[$theme]->appendAssets($js);
      }
    }
  }

  return $themes;
}