You are here

public function Asset::render in Mini site 8

Render asset.

Return value

string Rendered asset as content.

Overrides AssetInterface::render

File

src/Asset.php, line 324

Class

Asset
Class Asset.

Namespace

Drupal\minisite

Code

public function render() {
  $file_uri = $this->urlBag
    ->getUri();

  // Last check that asset file exist before render.
  if (!is_readable($file_uri)) {
    throw new AssetException(sprintf('Unable to render file "%s" as it does not exist', $file_uri));
  }
  $content = file_get_contents($file_uri);

  // Only process documents.
  if ($this
    ->isDocument()) {
    try {
      $processor = new PageProcessor($content, $this->urlBag);
      $processor
        ->process();
      $content = $processor
        ->content();
    } catch (PageProcessorException $exception) {

      // Simply pass-through as unprocessed content on processor exception and
      // fail for anything else.
    }
  }
  return $content;
}