Commit 2cdd6dd1 authored by frjo's avatar frjo
Browse files

Use the libraries module if installed to handle requirements check and status page information.

parent b022668b
......@@ -13,44 +13,44 @@ use Drupal\Component\Utility\Unicode;
function colorbox_requirements($phase) {
$requirements = array();
/*
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 (\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']
)),
);
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;
}
......@@ -112,6 +112,45 @@ function colorbox_page_attachments(array &$page) {
$already_added = TRUE;
}
/**
* 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;
}
/**
* Check if Colorbox should be active for the current URL.
*
......
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