function markdown_requirements in Markdown 3.0.x
Same name and namespace in other branches
- 8.2 markdown.install \markdown_requirements()
- 8 markdown.install \markdown_requirements()
Implements hook_requirements().
File
- ./
markdown.install, line 14 - Install, update and uninstall functions for the markdown module.
Code
function markdown_requirements($phase) {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$translation = \Drupal::translation();
$requirements = [];
if ($phase === 'runtime') {
$installed = [];
$build = [
'#theme' => 'table__markdown_parser_requirements',
'#header' => [
$translation
->translate('Supported Parsers'),
$translation
->translate('Installed Version'),
],
'#rows' => [],
];
/** @var \Drupal\markdown\MarkdownParserManagerInterface $parserManager */
$parserManager = \Drupal::service('plugin.manager.markdown.parser');
foreach ($parserManager
->all() as $name => $parser) {
$row = [];
if ($url = $parser
->getUrl()) {
$url = Url::fromUri($url, [
'attributes' => [
'target' => '_blank',
],
]);
$row[] = Link::fromTextAndUrl($parser
->getLabel(FALSE), $url);
}
else {
$row[] = $parser
->getLabel(FALSE);
}
if ($parser
->isInstalled()) {
$installed[] = $parser;
$row[] = $parser
->getVersion();
}
else {
$row[] = $translation
->translate('Not Installed');
}
$build['#rows'][] = [
'class' => $parser
->isInstalled() ? 'color-success' : 'color-warning',
'data' => $row,
];
}
$requirements['markdown'] = [
'title' => 'Markdown',
'severity' => REQUIREMENT_OK,
'value' => $translation
->formatPlural(count($installed), '1 parser installed', '@count parsers installed'),
];
if (!$installed) {
$requirements['markdown']['severity'] = REQUIREMENT_ERROR;
$requirements['markdown']['value'] .= '. ' . $translation
->translate('You must install at least one parser via Composer for the Markdown module to function properly.');
}
$requirements['markdown']['description'] = $renderer
->renderPlain($build);
}
return $requirements;
}