You are here

public function CriticalCssProvider::getCriticalCss in Critical CSS 8

Get critical CSS contents.

Return value

string The critical CSS contents

Overrides CriticalCssProviderInterface::getCriticalCss

1 call to CriticalCssProvider::getCriticalCss()
CriticalCssProvider::getMatchedFilePath in src/Asset/CriticalCssProvider.php
Get matched file path.

File

src/Asset/CriticalCssProvider.php, line 149

Class

CriticalCssProvider
Critical CSS Provider.

Namespace

Drupal\critical_css\Asset

Code

public function getCriticalCss() {

  // Return previous result, if any.
  if ($this->isAlreadyProcessed) {
    return $this->criticalCss;
  }
  $this->isAlreadyProcessed = TRUE;

  // Get possible file paths and return first match.
  $filePaths = $this
    ->getFilePaths();
  foreach ($filePaths as $filePath) {
    if (is_file($filePath)) {
      $this->matchedFilePath = $filePath;
      $this->criticalCss = trim(file_get_contents($filePath));
      break;
    }
  }
  return $this->criticalCss;
}