You are here

public function UltimenuManager::getSkins in Ultimenu 8

Retrieves stored CSS files for Ultimenu skin options.

Return value

array An array of available CSS files.

Overrides UltimenuManagerInterface::getSkins

File

src/UltimenuManager.php, line 630

Class

UltimenuManager
Manages Ultimenu plugin.

Namespace

Drupal\ultimenu

Code

public function getSkins() {
  if (!isset($this->skins)) {
    if ($cache = $this->cacheBackend
      ->get($this->cacheKey . ':skin')) {
      $this->skins = $cache->data;
    }
    else {
      $theme_default = $this
        ->getConfig('system.theme')
        ->get('default');
      $theme_skin = drupal_get_path('theme', $theme_default) . '/css/ultimenu';
      $custom_skin = $this
        ->getSetting('skins');
      $module_skin = drupal_get_path('module', 'ultimenu') . '/skins';
      $mask = '/.css$/';
      $files = [];
      if (is_dir($module_skin)) {
        foreach (file_scan_directory($module_skin, $mask) as $filename => $file) {
          $files[$filename] = $file;
        }
      }
      if (!empty($custom_skin) && is_dir($custom_skin)) {
        foreach (file_scan_directory($custom_skin, $mask) as $filename => $file) {
          $files[$filename] = $file;
        }
      }
      if (is_dir($theme_skin)) {
        foreach (file_scan_directory($theme_skin, $mask) as $filename => $file) {
          $files[$filename] = $file;
        }
      }
      if ($files) {
        $skins = [];
        foreach ($files as $file) {
          $uri = $file->uri;
          $name = $file->name;

          // Simplify lengthy deep directory structure.
          if (strpos($uri, $module_skin) !== FALSE) {
            $uri = "module|" . $name;
          }
          elseif (!empty($custom_skin) && strpos($uri, $custom_skin) !== FALSE) {
            $uri = "custom|" . $name;
          }
          elseif (is_dir($theme_skin) && strpos($uri, $theme_skin) !== FALSE) {
            $uri = "theme|" . $name;
          }

          // Convert file name to CSS friendly for option label and styling.
          $skins[$uri] = Html::cleanCssIdentifier(Unicode::strtolower($name));
        }
        $this->cacheBackend
          ->set($this->cacheKey . ':skin', $skins, Cache::PERMANENT, array(
          'skin',
        ));
        $this->skins = $skins;
      }
    }
  }
  return $this->skins;
}