You are here

protected function CssCollectionRenderer::getCriticalCssAsset in Critical CSS 8

Get critical CSS element.

It's an array that should be placed into $css_assets array from render() method. It will contain date in two cases: 1) When a critical CSS file is found. 2) When Twig's debug is enabled.

Return value

array|null Null if no critical CSS found nor Twig's debug is enabled. Otherwise, an array with the following items:

  • '#type'
  • '#tag'
  • '#attributes'
  • '#value'
1 call to CssCollectionRenderer::getCriticalCssAsset()
CssCollectionRenderer::render in src/Asset/CssCollectionRenderer.php
Renders an asset collection.

File

src/Asset/CssCollectionRenderer.php, line 117

Class

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

Namespace

Drupal\critical_css\Asset

Code

protected function getCriticalCssAsset() {
  $criticalCssAsset = NULL;
  $debugInfo = $this
    ->getDebugInfo();
  $criticalCss = $this->criticalCssProvider
    ->getCriticalCss();
  if ($criticalCss || $debugInfo['start'] || $debugInfo['end']) {
    $criticalCssAsset = [
      '#type' => 'html_tag',
      '#tag' => 'style',
      '#attributes' => [
        'id' => 'critical-css',
      ],
      '#value' => Markup::create($debugInfo['start'] . $criticalCss . $debugInfo['end']),
    ];
  }
  return $criticalCssAsset;
}