You are here

public function Skin::load in Forena Reports 8

Same name and namespace in other branches
  1. 7.5 src/Skin.php \Drupal\forena\Skin::load()

Load the skin based on the name.

Parameters

string $name: path/name of skin.

Return value

\Drupal\forena\Skin

1 call to Skin::load()
Skin::__construct in src/Skin.php

File

src/Skin.php, line 112
Implements \Drupal\forena\Skins

Class

Skin
Class Skin A skin is a collectio of css and js files that need to get used by an application or reports. Skins are idntified by .fri files contained in the report directory.

Namespace

Drupal\forena

Code

public function load($name) {
  $fileSystem = $this
    ->reportFileSystem();
  $path_info = [];
  if (!$name) {
    $name = $this->default_skin;
  }
  if ($name) {

    //Check for an info file
    $this->info = [];
    if ($fileSystem
      ->exists($name . '.skin.yml')) {
      $this->info = Skin::parseYml($fileSystem
        ->contents($name . '.skin.yml'));
      $path_info = $fileSystem
        ->pathinfo($name . '.skin.yml');
    }

    // add and process sytlesheets
    if ($this->info) {
      $this->info['dir'] = '/' . $path_info['dirname'];
      $this
        ->dataService()
        ->setContext('skin', $this->info);
    }
  }

  // Replace tokens in css files based on paths.
  $this->library = [];
  if (isset($this->info['library'])) {
    $library = $this->info['library'];
    $new_library = $library;

    // Process CSS
    if (isset($library['css'])) {
      unset($new_library['css']);
      foreach ($library['css'] as $level => $files) {
        $new_library[$level] = [];
        foreach ($files as $file => $options) {
          $new_file = $this->replacer
            ->replace($file, TRUE);
          $new_library['css'][$level][$new_file] = $options;
        }
      }
    }

    // Process JS
    if (isset($library['js'])) {
      unset($new_library['js']);
      foreach ($library['js'] as $file => $options) {
        $new_file = $this->replacer
          ->replace($file, TRUE);
        $new_library['js'][$new_file] = $options;
      }
    }
    $this->library = $new_library;
  }
  return $this;
}