Commit a35fb306 authored by osman's avatar osman

Fix requirements with correct library

parent 7d98315b
...@@ -9,33 +9,27 @@ ...@@ -9,33 +9,27 @@
* Implements hook_requirements(). * Implements hook_requirements().
*/ */
function lazy_requirements($phase) { function lazy_requirements($phase) {
$requirements = []; if ($phase != 'runtime') {
return [];
}
if ($phase == 'runtime') { $library = Drupal::service('library.discovery')->getLibraryByName('lazy', 'lazysizes');
$library = Drupal::service('library.discovery') $library_exists = FALSE;
->getLibraryByName('lazy', 'lazy-blazy');
$has_blazy = FALSE;
if ($library['js']) {
foreach ($library['js'] as $js) { foreach ($library['js'] as $js) {
if (($js['type'] == 'file') && file_exists(DRUPAL_ROOT . '/' . $js['data'])) { if (strpos($js['data'], 'lazysizes.min.js') !== FALSE) {
$has_blazy = TRUE; $library_exists = file_exists(DRUPAL_ROOT . '/' . $js['data']);
}
} }
} }
$requirements['blazy'] = [ return [
'title' => t('bLazy library'), 'lazy_lazysizes' => [
'title' => t('Lazysizes library'),
'value' => $library_exists ? $library['version'] : t('Not installed'),
'description' => $library_exists ? '' : t('The Lazysizes library needs to be <a href="@url">downloaded</a> and extracted into the /libraries/lazysizes folder in your Drupal installation directory.', ['@url' => 'https://github.com/aFarkas/lazysizes/archive/5.1.1.zip']),
'severity' => $library_exists ? REQUIREMENT_OK : REQUIREMENT_ERROR,
],
]; ];
$requirements['blazy']['value'] = $has_blazy ? t('Enabled') : t('Not found');
$requirements['blazy']['severity'] = $has_blazy ? REQUIREMENT_OK : REQUIREMENT_WARNING;
if (!$has_blazy) {
$requirements['blazy']['description'] = t('Lazy-load modules requires the bLazy library. See README.md file for instructions.');
}
}
return $requirements;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment