keyboard_shortcuts-1.0.0/keyboard_shortcuts.install
keyboard_shortcuts.install
<?php
/**
* @file
* Installation actions for Keyboard Shortcuts.
*/
/**
* Implements hook_install().
*/
function keyboard_shortcuts_install() {
$requirements = keyboard_shortcuts_requirements('runtime');
if ($requirements['mousetrap_library_downloaded']['severity'] == REQUIREMENT_ERROR) {
\Drupal::messenger()->addWarning($requirements['mousetrap_library_downloaded']['description']);
}
}
/**
* Implements hook_requirements().
*/
function keyboard_shortcuts_requirements($phase) {
// Verify Mousetrap is enabled.
if ($phase == 'runtime') {
$library = \Drupal::service('library.discovery')->getLibraryByName('keyboard_shortcuts', 'mousetrap');
$library_exists = file_exists(DRUPAL_ROOT . '/' . $library['js'][0]['data']);
$message = t('Keyboard shortcuts module requires the Mousetrap library. <a href=":moustrap_link">Download Mousetrap library</a> and unzip into /libraries/mousetrap.', [
':mousetrap_link' => 'https://github.com/ccampbell/mousetrap/archive/master.zip',
]);
return [
'mousetrap_library_downloaded' => [
'title' => t('Mousetrap library'),
'value' => $library_exists ? t('Installed') : t('Not installed'),
'description' => $library_exists ? '' : $message,
'severity' => $library_exists ? REQUIREMENT_OK : REQUIREMENT_ERROR,
],
];
}
}
