protected function StyleDiscovery::getSortedThemeDirectories

Gets the theme directories sorted by hierarchy.

Return value

string[] The sorted theme directories array.

File

paragraphs_collection/src/StyleDiscovery.php, line 216

Class

StyleDiscovery
Provides common helper methods for style discovery. @todo Create documentation for style discovery https://www.drupal.org/node/2837995

Namespace

Drupal\paragraphs_collection

Code

protected function getSortedThemeDirectories() {
  $theme_directories = $this->themeHandler
    ->getThemeDirectories();
  $themes = $this->themeHandler
    ->listInfo();
  $sorted_themes = [];

  // Loop over all themes and loop over their base themes.
  foreach ($themes as $theme) {
    if (isset($theme->base_themes)) {
      foreach (array_keys($theme->base_themes) as $base_theme) {

        // If the theme has not been added yet, add it.
        if (!isset($sorted_themes[$base_theme])) {
          $sorted_themes[$base_theme] = TRUE;
        }
      }
    }

    // If the theme has not been added yet, add it.
    if (!isset($sorted_themes[$theme
      ->getName()])) {
      $sorted_themes[$theme
        ->getName()] = TRUE;
    }
  }

  // Sort the theme directories based on the theme keys.
  return array_replace($sorted_themes, $theme_directories);
}