Commit 01793ef3 authored by frjo's avatar frjo Committed by frjo
Browse files

Issue #2683947 by Sam152, frjo: Move away from the libraries module for...

Issue #2683947 by Sam152, frjo: Move away from the libraries module for detecting the library in hook_requirements
parent 056e2414
......@@ -46,7 +46,7 @@ Installation:
2. Download and unpack the Colorbox plugin in "libraries".
Make sure the path to the plugin file becomes:
"libraries/colorbox/jquery.colorbox-min.js"
Link: https://github.com/jackmoore/colorbox/archive/1.x.zip
Link: https://github.com/jackmoore/colorbox/archive/master.zip
Drush users can use the command "drush colorbox-plugin".
3. Go to "Administer" -> "Extend" and enable the Colorbox module.
......
......@@ -11,46 +11,15 @@ use Drupal\Component\Utility\Unicode;
* Implements hook_requirements().
*/
function colorbox_requirements($phase) {
$requirements = array();
$library = \Drupal::service('library.discovery')->getLibraryByName('colorbox', 'colorbox');
$library_exists = file_exists(DRUPAL_ROOT . '/' . $library['js'][0]['data']);
if (\Drupal::moduleHandler()->moduleExists('libraries')) {
if ($phase == 'runtime') {
$library = libraries_detect('colorbox');
$error_type = isset($library['error']) ? Unicode::ucfirst($library['error']) : '';
$error_message = isset($library['error message']) ? $library['error message'] : '';
if (empty($library['installed'])) {
$requirements['colorbox_plugin'] = array(
'title' => t('Colorbox plugin'),
'value' => t('@e: At least @a', array('@e' => $error_type, '@a' => COLORBOX_MIN_PLUGIN_VERSION)),
'severity' => REQUIREMENT_ERROR,
'description' => t('@error You need to download the <a href=":colorbox_link">Colorbox plugin</a>, extract the archive and place the colorbox directory in the %path directory on your server.', array(
'@error' => $error_message,
':colorbox_link' => $library['download url'],
'%path' => 'libraries',
)),
);
}
elseif (version_compare($library['version'], COLORBOX_MIN_PLUGIN_VERSION, '>=')) {
$requirements['colorbox_plugin'] = array(
'title' => t('Colorbox plugin'),
'severity' => REQUIREMENT_OK,
'value' => $library['version'],
);
}
else {
$requirements['colorbox_plugin'] = array(
'title' => t('Colorbox plugin'),
'value' => t('At least @a', array('@a' => COLORBOX_MIN_PLUGIN_VERSION)),
'severity' => REQUIREMENT_ERROR,
'description' => t('You need to download a later version of the <a href=":colorbox_link">Colorbox plugin</a> and replace the old version located in the %path directory on your server.', array(
':colorbox_link' => $library['download url'],
'%path' => $library['library path']
)),
);
}
}
}
return $requirements;
return [
'colorbox_library_downloaded' => [
'title' => t('Colorbox library'),
'value' => $library_exists ? t('Installed') : t('Not installed'),
'description' => $library_exists ? '' : t('The Colorbox library needs to be <a href="@url">downloaded</a> and extracted into the /libraries/colorbox folder in your Drupal installation directory.', ['@url' => 'https://github.com/jackmoore/colorbox/archive/master.zip']),
'severity' => $library_exists ? REQUIREMENT_OK : REQUIREMENT_ERROR,
],
];
}
......@@ -2,15 +2,9 @@
/**
* @file
* A light-weight, customizable lightbox plugin for jQuery 1.3
* A light-weight, customizable lightbox plugin.
*/
/**
* The default path to the Colorbox directory.
*/
define('COLORBOX_MIN_PLUGIN_VERSION', '1.6.1');
/**
* Implements hook_theme().
*/
......@@ -26,42 +20,3 @@ function colorbox_theme() {
),
);
}
/**
* Implements hook_libraries_info().
*/
function colorbox_libraries_info() {
$libraries['colorbox'] = array(
'name' => 'Colorbox plugin',
'vendor url' => 'http://www.jacklmoore.com/colorbox',
'download url' => 'https://github.com/jackmoore/colorbox/archive/1.x.zip',
'version arguments' => array(
'file' => 'jquery.colorbox-min.js',
'pattern' => '@(?i:Colorbox)\sv?([0-9\.a-z]+)@',
'lines' => 5,
),
'files' => array(
'js' => array(
'jquery.colorbox-min.js',
),
),
'variants' => array(
'minified' => array(
'files' => array(
'js' => array(
'jquery.colorbox-min.js',
),
),
),
'source' => array(
'files' => array(
'js' => array(
'jquery.colorbox.js',
),
),
),
),
);
return $libraries;
}
......@@ -8,7 +8,7 @@
/**
* The Colorbox plugin URI.
*/
define('COLORBOX_DOWNLOAD_URI', 'https://github.com/jackmoore/colorbox/archive/1.x.zip');
define('COLORBOX_DOWNLOAD_URI', 'https://github.com/jackmoore/colorbox/archive/master.zip');
define('COLORBOX_DOWNLOAD_PREFIX', 'colorbox-');
/**
......
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