You are here

protected function CssCollectionRenderer::getDebugInfo in Critical CSS 8

Get critical CSS debug info about current request.

Return value

array Array with two items (start and end string) ready to be used as debug info.

1 call to CssCollectionRenderer::getDebugInfo()
CssCollectionRenderer::getCriticalCssAsset in src/Asset/CssCollectionRenderer.php
Get critical CSS element.

File

src/Asset/CssCollectionRenderer.php, line 195

Class

CssCollectionRenderer
Decorates the CSS collection renderer service, adds Critical CSS.

Namespace

Drupal\critical_css\Asset

Code

protected function getDebugInfo() {
  $matchedFilePath = $this->criticalCssProvider
    ->getMatchedFilePath();

  // Show debug info if twig debug is on.
  $debugInfoStart = NULL;
  $debugInfoEnd = NULL;
  if ($this->twig
    ->isDebug()) {
    $filePaths = $this->criticalCssProvider
      ->getFilePaths();
    $debugInfoStart = "\n/* CRITICAL CSS DEBUG */\n";
    $debugInfoStart .= "/* FILE NAME SUGGESTIONS:\n";
    foreach ($filePaths as $filePath) {
      $flag = $filePath === $matchedFilePath ? 'x' : '*';
      $debugInfoStart .= "\t {$flag} {$filePath}\n";
    }
    $debugInfoStart .= "*/\n";
    if ($matchedFilePath) {
      $debugInfoStart .= '/* BEGIN OUTPUT from ' . Html::escape($matchedFilePath) . " */\n";
      $debugInfoEnd = "\n/* END OUTPUT from " . Html::escape($matchedFilePath) . " */\n";
    }
    else {
      $debugInfoStart .= "/* NONE MATCHED. THIS USUALLY HAPPENS WHEN YOU ARE LOGGED IN. LOG OUT AND TRY AGAIN AS AN ANONYMOUS USER. */\n";
    }
  }
  return [
    'start' => $debugInfoStart,
    'end' => $debugInfoEnd,
  ];
}