You are here

public function BaseParser::loadPath in Markdown 3.0.x

Loads a cached ParsedMarkdown object for a local file system path.

Parameters

string $id: A unique identifier that will be used to cache the parsed markdown.

string $path: 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.

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

Return value

\Drupal\markdown\ParsedMarkdownInterface A ParsedMarkdown object.

Throws

\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException When the provided $path does not exist in the local file system.

Overrides MarkdownParserInterface::loadPath

File

src/Plugin/Markdown/BaseParser.php, line 393

Class

BaseParser
Plugin annotation @MarkdownParser( id = "_broken", label = @Translation("Missing Parser"), )

Namespace

Drupal\markdown\Plugin\Markdown

Code

public function loadPath($id, $path, LanguageInterface $language = NULL) {

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