public function Markdown::loadUrl in Markdown 8.2
Same name and namespace in other branches
- 3.0.x src/Markdown.php \Drupal\markdown\Markdown::loadUrl()
Loads a cached ParsedMarkdown object based on a URL.
Parameters
string $url: The external URL 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 $url.
\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\MarkdownUrlNotExistsException
Overrides MarkdownInterface::loadUrl
File
- src/
Markdown.php, line 140
Class
- Markdown
- Markdown service.
Namespace
Drupal\markdownCode
public function loadUrl($url, $id = NULL, LanguageInterface $language = NULL) {
if ($url instanceof Url) {
$url = $url
->setAbsolute()
->toString();
}
else {
$url = (string) $url;
}
if (!$id) {
$id = $url;
}
if (!($parsed = $this
->load($id))) {
$response = $this->httpClient
->get($url);
if ($response
->getStatusCode() < 200 || $response
->getStatusCode() >= 400) {
throw new MarkdownUrlNotExistsException($url);
}
$parsed = $this
->save($id, $this
->parse($response
->getBody()
->getContents(), $language));
}
return $parsed;
}