function syntaxhighlighter_requirements in Syntax Highlighter 8
Same name and namespace in other branches
- 6.2 syntaxhighlighter.install \syntaxhighlighter_requirements()
- 6 syntaxhighlighter.install \syntaxhighlighter_requirements()
- 7.2 syntaxhighlighter.install \syntaxhighlighter_requirements()
- 7 syntaxhighlighter.install \syntaxhighlighter_requirements()
Implements hook_requirements().
Make sure the user has installed the SyntaxHighlighter library.
File
- ./
syntaxhighlighter.install, line 42 - Syntax Highlighter module installation file.
Code
function syntaxhighlighter_requirements($phase) {
$requirements = [];
if ($phase == 'install') {
// Make sure the libraries function is available during installation phase.
if (!function_exists('libraries_get_path')) {
/*
* Make sure the libraries module has been registered. This covers the
* case when syntaxhighlighter_requirements() is run from a custom
* installation profile which depends on syntaxhighlighter.
*/
if (!Drupal::moduleHandler()
->moduleExists('libraries')) {
system_rebuild_module_data();
}
module_load_include('module', 'libraries');
}
}
$lib_location = libraries_get_path('syntaxhighlighter');
if (!$lib_location) {
$requirements['syntaxhighlighter']['severity'] = REQUIREMENT_ERROR;
$requirements['syntaxhighlighter']['description'] = t('The required SyntaxHighlighter Javascript library is not installed. See <a href=":link">the Syntax Highlighter module README.txt file</a> for instructions.', [
':link' => Url::FromUri('internal:/' . drupal_get_path('module', 'syntaxhighlighter') . '/README.txt')
->toString(),
]);
}
if ($phase === 'runtime') {
$requirements['syntaxhighlighter']['title'] = t('Syntax Highlighter');
$library = libraries_detect('syntaxhighlighter');
if (!$library || !$library['installed']) {
$requirements['syntaxhighlighter']['value'] = t('Not installed');
}
else {
$requirements['syntaxhighlighter']['value'] = !empty($library['version']) ? $library['version'] : t('Installed');
}
}
return $requirements;
}