markdown.install in Markdown 3.0.x
Same filename and directory in other branches
Install, update and uninstall functions for the markdown module.
File
markdown.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the markdown module.
*/
use Drupal\Core\Link;
use Drupal\Core\Url;
/**
* Implements hook_requirements().
*/
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;
}
Functions
Name | Description |
---|---|
markdown_requirements | Implements hook_requirements(). |