You are here

public function Markdown::loadFile in Markdown 8.2

Loads a cached ParsedMarkdown object based on system file.

Parameters

string $filename: The local file system path of a markdown file to parse if the cached ParsedMarkdown object doesn't yet exist. Once parsed, its identifier will be set to the provided $id and then cached.

string $id: Optional. A unique identifier for caching the parsed markdown. If not set, one will be generated automatically based on the provided $filename.

\Drupal\Core\Language\LanguageInterface $language: Optional. The language of the markdown that is being parsed.

Return value

\Drupal\markdown\Render\ParsedMarkdownInterface A ParsedMarkdown object.

Throws

\Drupal\markdown\Exception\MarkdownFileNotExistsException

Overrides MarkdownInterface::loadFile

1 call to Markdown::loadFile()
Markdown::loadPath in src/Markdown.php

File

src/Markdown.php, line 111

Class

Markdown
Markdown service.

Namespace

Drupal\markdown

Code

public function loadFile($path, $id = NULL, LanguageInterface $language = NULL) {
  $realpath = $this->fileSystem
    ->realpath($path) ?: $path;
  if (!file_exists($realpath)) {
    throw new MarkdownFileNotExistsException($realpath);
  }
  if (!$id) {
    $id = $this->fileSystem
      ->basename($realpath) . Crypt::hashBase64($realpath);
  }

  // Append the file modification time as a cache buster in case it changed.
  $id = "{$id}:" . filemtime($realpath);
  return $this
    ->load($id) ?: $this
    ->save($id, $this
    ->parse(file_get_contents($realpath) ?: '', $language));
}