Commit ad5e7877 authored by grisendo's avatar grisendo
Browse files

Code refactor for 8.x

parent 8ba01e89
<?php
/**
* @file
* Administrative page callbacks for the colorbox module.
*/
/**
* General configuration form for controlling the colorbox behaviour.
*/
function colorbox_admin_settings() {
drupal_add_js(drupal_get_path('module', 'colorbox') . '/js/colorbox_admin_settings.js', array('preprocess' => FALSE));
$library = libraries_detect('colorbox');
if (module_exists('insert')) {
$form['colorbox_insert_module'] = array(
'#type' => 'fieldset',
'#title' => t('Insert module settings'),
);
$image_styles = image_style_options(FALSE);
$form['colorbox_insert_module']['colorbox_image_style'] = array(
'#type' => 'select',
'#title' => t('Image style'),
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
'#default_value' => variable_get('colorbox_image_style', ''),
'#description' => t('Select which image style to use for viewing images in the colorbox.'),
);
$form['colorbox_insert_module']['colorbox_insert_gallery'] = array(
'#type' => 'radios',
'#title' => t('Insert image gallery'),
'#default_value' => variable_get('colorbox_insert_gallery', 0),
'#options' => array(0 => t('Per page gallery'), 3 => t('No gallery')),
'#description' => t('Should the gallery be all images on the page (default) or disabled.'),
);
}
$form['colorbox_extra_features'] = array(
'#type' => 'fieldset',
'#title' => t('Extra features'),
);
$form['colorbox_extra_features']['colorbox_load'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Colorbox load'),
'#default_value' => variable_get('colorbox_load', 0),
'#description' => t('This enables custom links that can open forms and paths in a Colorbox. Add the class "colorbox-load" to the link and build the url like this for paths "[path]?width=500&height=500&iframe=true" or "[path]?width=500&height=500" if you don\'t want an iframe. Other modules may activate this for easy Colorbox integration.'),
);
$form['colorbox_extra_features']['colorbox_inline'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Colorbox inline'),
'#default_value' => variable_get('colorbox_inline', 0),
'#description' => t('This enables custom links that can open inline content in a Colorbox. Add the class "colorbox-inline" to the link and build the url like this "?width=500&height=500&inline=true#id-of-content". Other modules may activate this for easy Colorbox integration.'),
);
$form['colorbox_custom_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Styles and options'),
);
$colorbox_styles = array(
'default' => t('Default'),
'plain' => t('Plain (mainly for images)'),
'stockholmsyndrome' => t('Stockholm Syndrome'),
$library['library path'] . '/example1' => t('Example 1'),
$library['library path'] . '/example2' => t('Example 2'),
$library['library path'] . '/example3' => t('Example 3'),
$library['library path'] . '/example4' => t('Example 4'),
$library['library path'] . '/example5' => t('Example 5'),
'none' => t('None'),
);
$form['colorbox_custom_settings']['colorbox_style'] = array(
'#type' => 'select',
'#title' => t('Style'),
'#options' => $colorbox_styles,
'#default_value' => variable_get('colorbox_style', 'default'),
'#description' => t('Select the style to use for the Colorbox. The example styles are the ones that come with the Colorbox plugin. Select "None" if you have added Colorbox styles to your theme.'),
);
$form['colorbox_custom_settings']['colorbox_custom_settings_activate'] = array(
'#type' => 'radios',
'#title' => t('Options'),
'#options' => array(0 => t('Default'), 1 => t('Custom')),
'#default_value' => variable_get('colorbox_custom_settings_activate', 0),
'#description' => t('Use the default or custom options for Colorbox.'),
'#prefix' => '<div class="colorbox-custom-settings-activate">',
'#suffix' => '</div>',
);
$js_hide = variable_get('colorbox_custom_settings_activate', 0) ? '' : ' js-hide';
$form['colorbox_custom_settings']['wrapper_start'] = array(
'#markup' => '<div class="colorbox-custom-settings' . $js_hide . '">',
);
$form['colorbox_custom_settings']['colorbox_transition_type'] = array(
'#type' => 'radios',
'#title' => t('Transition type'),
'#options' => array('elastic' => t('Elastic'), 'fade' => t('Fade'), 'none' => t('None')),
'#default_value' => variable_get('colorbox_transition_type', 'elastic'),
'#description' => t('The transition type.'),
);
$form['colorbox_custom_settings']['colorbox_transition_speed'] = array(
'#type' => 'select',
'#title' => t('Transition speed'),
'#options' => drupal_map_assoc(array(100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600)),
'#default_value' => variable_get('colorbox_transition_speed', 350),
'#description' => t('Sets the speed of the fade and elastic transitions, in milliseconds.'),
);
$form['colorbox_custom_settings']['colorbox_opacity'] = array(
'#type' => 'select',
'#title' => t('Opacity'),
'#options' => drupal_map_assoc(array('0', '0.10', '0.15', '0.20', '0.25', '0.30', '0.35', '0.40', '0.45', '0.50', '0.55', '0.60', '0.65', '0.70', '0.75', '0.80', '0.85', '0.90', '0.95', '1')),
'#default_value' => variable_get('colorbox_opacity', '0.85'),
'#description' => t('The overlay opacity level. Range: 0 to 1.'),
);
$form['colorbox_custom_settings']['colorbox_text_current'] = array(
'#type' => 'textfield',
'#title' => t('Current'),
'#default_value' => variable_get('colorbox_text_current', '{current} of {total}'),
'#size' => 30,
'#description' => t('Text format for the content group / gallery count. {current} and {total} are detected and replaced with actual numbers while Colorbox runs.'),
);
$form['colorbox_custom_settings']['colorbox_text_previous'] = array(
'#type' => 'textfield',
'#title' => t('Previous'),
'#default_value' => variable_get('colorbox_text_previous', '« Prev'),
'#size' => 30,
'#description' => t('Text for the previous button in a shared relation group.'),
);
$form['colorbox_custom_settings']['colorbox_text_next'] = array(
'#type' => 'textfield',
'#title' => t('Next'),
'#default_value' => variable_get('colorbox_text_next', 'Next »'),
'#size' => 30,
'#description' => t('Text for the next button in a shared relation group.'),
);
$form['colorbox_custom_settings']['colorbox_text_close'] = array(
'#type' => 'textfield',
'#title' => t('Close'),
'#default_value' => variable_get('colorbox_text_close', 'Close'),
'#size' => 30,
'#description' => t('Text for the close button. The "Esc" key will also close Colorbox.'),
);
$form['colorbox_custom_settings']['colorbox_overlayclose'] = array(
'#type' => 'checkbox',
'#title' => t('Overlay close'),
'#default_value' => variable_get('colorbox_overlayclose', 1),
'#description' => t('Enable closing Colorbox by clicking on the background overlay.'),
);
$form['colorbox_custom_settings']['colorbox_maxwidth'] = array(
'#type' => 'textfield',
'#title' => t('Max width'),
'#default_value' => variable_get('colorbox_maxwidth', '98%'),
'#size' => 30,
'#description' => t('Set a maximum width for loaded content. Example: "100%", 500, "500px".'),
);
$form['colorbox_custom_settings']['colorbox_maxheight'] = array(
'#type' => 'textfield',
'#title' => t('Max height'),
'#default_value' => variable_get('colorbox_maxheight', '98%'),
'#size' => 30,
'#description' => t('Set a maximum height for loaded content. Example: "100%", 500, "500px".'),
);
$form['colorbox_custom_settings']['colorbox_initialwidth'] = array(
'#type' => 'textfield',
'#title' => t('Initial width'),
'#default_value' => variable_get('colorbox_initialwidth', '300'),
'#size' => 30,
'#description' => t('Set the initial width, prior to any content being loaded. Example: "100%", 500, "500px".'),
);
$form['colorbox_custom_settings']['colorbox_initialheight'] = array(
'#type' => 'textfield',
'#title' => t('Initial height'),
'#default_value' => variable_get('colorbox_initialheight', '250'),
'#size' => 30,
'#description' => t('Set the initial height, prior to any content being loaded. Example: "100%", 500, "500px".'),
);
$form['colorbox_custom_settings']['colorbox_fixed'] = array(
'#type' => 'checkbox',
'#title' => t('Fixed'),
'#default_value' => variable_get('colorbox_fixed', 1),
'#description' => t('If the Colorbox should be displayed in a fixed position within the visitor\'s viewport or relative to the document.'),
);
$form['colorbox_custom_settings']['colorbox_slideshow_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Slideshow settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_slideshow'] = array(
'#type' => 'radios',
'#title' => t('Slideshow'),
'#options' => array(0 => t('Off'), 1 => t('On')),
'#default_value' => variable_get('colorbox_slideshow', 0),
'#description' => t('An automatic slideshow to a content group / gallery.'),
'#prefix' => '<div class="colorbox-slideshow-settings-activate">',
'#suffix' => '</div>',
);
$form['colorbox_custom_settings']['colorbox_scrolling'] = array(
'#type' => 'radios',
'#title' => t('Scrollbars'),
'#options' => array(1 => t('On'), 0 => t('Off')),
'#default_value' => variable_get('colorbox_scrolling', 1),
'#description' => t('If false, Colorbox will hide scrollbars for overflowing content. This could be used on conjunction with the resize method for a smoother transition if you are appending content to an already open instance of Colorbox.'),
);
$js_hide = variable_get('colorbox_slideshow', 0) ? '' : ' js-hide';
$form['colorbox_custom_settings']['colorbox_slideshow_settings']['wrapper_start'] = array(
'#markup' => '<div class="colorbox-slideshow-settings' . $js_hide . '">',
);
$form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_slideshowauto'] = array(
'#type' => 'checkbox',
'#title' => t('Slideshow autostart'),
'#default_value' => variable_get('colorbox_slideshowauto', 1),
'#description' => t('If the slideshow should automatically start to play.'),
);
$form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_slideshowspeed'] = array(
'#type' => 'select',
'#title' => t('Slideshow speed'),
'#options' => drupal_map_assoc(array(1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000)),
'#default_value' => variable_get('colorbox_slideshowspeed', 2500),
'#description' => t('Sets the speed of the slideshow, in milliseconds.'),
);
$form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_text_start'] = array(
'#type' => 'textfield',
'#title' => t('Start slideshow'),
'#default_value' => variable_get('colorbox_text_start', 'start slideshow'),
'#size' => 30,
'#description' => t('Text for the slideshow start button.'),
);
$form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_text_stop'] = array(
'#type' => 'textfield',
'#title' => t('Stop slideshow'),
'#default_value' => variable_get('colorbox_text_stop', 'stop slideshow'),
'#size' => 30,
'#description' => t('Text for the slideshow stop button.'),
);
$form['colorbox_custom_settings']['colorbox_slideshow_settings']['wrapper_stop'] = array(
'#markup' => '</div>',
);
$form['colorbox_custom_settings']['wrapper_stop'] = array(
'#markup' => '</div>',
);
$form['colorbox_advanced_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['colorbox_advanced_settings']['colorbox_mobile_detect'] = array(
'#type' => 'radios',
'#title' => t('Mobile detection'),
'#options' => array(1 => t('On'), 0 => t('Off')),
'#default_value' => variable_get('colorbox_mobile_detect', 1),
'#description' => t('If on (default) Colorbox will not be active for devices with a the max width set below.'),
);
$form['colorbox_advanced_settings']['colorbox_mobile_device_width'] = array(
'#type' => 'textfield',
'#title' => t('Device with'),
'#default_value' => variable_get('colorbox_mobile_device_width', '480px'),
'#size' => 30,
'#description' => t('Set the mobile device max with. Default: 480px.'),
'#states' => array(
'visible' => array(
':input[name="colorbox_mobile_detect"]' => array('value' => '1'),
),
),
);
$form['colorbox_advanced_settings']['colorbox_caption_trim'] = array(
'#type' => 'radios',
'#title' => t('Caption shortening'),
'#options' => array(0 => t('Default'), 1 => t('Yes')),
'#default_value' => variable_get('colorbox_caption_trim', 0),
'#description' => t('If the caption should be made shorter in the Colorbox to avoid layout problems. The default is to shorten for the example styles, they need it, but not for other styles.'),
);
$form['colorbox_advanced_settings']['colorbox_caption_trim_length'] = array(
'#type' => 'select',
'#title' => t('Caption max length'),
'#options' => drupal_map_assoc(array(40, 45, 50, 55, 60, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120)),
'#default_value' => variable_get('colorbox_caption_trim_length', 75),
'#states' => array(
'visible' => array(
':input[name="colorbox_caption_trim"]' => array('value' => '1'),
),
),
);
$form['colorbox_advanced_settings']['colorbox_visibility'] = array(
'#type' => 'radios',
'#title' => t('Show Colorbox on specific pages'),
'#options' => array(0 => t('All pages except those listed'), 1 => t('Only the listed pages')),
'#default_value' => variable_get('colorbox_visibility', 0),
);
$form['colorbox_advanced_settings']['colorbox_pages'] = array(
'#type' => 'textarea',
'#title' => '<span class="element-invisible">' . t('Pages') . '</span>',
'#default_value' => variable_get('colorbox_pages', "admin*\nimagebrowser*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit\nprint/*\nprintpdf/*\nsystem/ajax\nsystem/ajax/*"),
'#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
);
$form['colorbox_advanced_settings']['colorbox_compression_type'] = array(
'#type' => 'radios',
'#title' => t('Choose Colorbox compression level'),
'#options' => array(
'minified' => t('Production (Minified)'),
'source' => t('Development (Uncompressed Code)'),
),
'#default_value' => variable_get('colorbox_compression_type', 'minified'),
);
return system_settings_form($form);
}
name = Colorbox
description = A light-weight, customizable lightbox plugin for jQuery 1.4.3+.
dependencies[] = libraries (2.x)
core = 7.x
configure = admin/config/media/colorbox
files[] = views/colorbox_handler_field_colorbox.inc
name: 'Colorbox'
type: module
description: 'A light-weight, customizable lightbox plugin for jQuery 1.4.3+.'
core: 8.x
configure: admin/config/media/colorbox
......@@ -9,11 +9,13 @@
* Implements hook_requirements().
*/
function colorbox_requirements($phase) {
return;
$requirements = array();
if ($phase == 'runtime') {
$t = get_t();
$library = libraries_detect('colorbox');
//$t = get_t();
$t = 't';
//$library = libraries_detect('colorbox');
$error_type = isset($library['error']) ? drupal_ucfirst($library['error']) : '';
$error_message = isset($library['error message']) ? $library['error message'] : '';
......@@ -118,3 +120,11 @@ function colorbox_update_7202() {
return $ret;
}
/**
* Converts variables to configuration.
*/
function colorbox_update_8000() {
// TO-DO
}
......@@ -42,6 +42,7 @@ function colorbox_theme() {
'entity' => NULL,
'node' => NULL, // Left for legacy support.
'field' => array(),
'path' => drupal_get_path('module', 'colorbox') . '/templates',
'display_settings' => array(),
),
'file' => 'colorbox.theme.inc',
......@@ -49,63 +50,38 @@ function colorbox_theme() {
);
}
/**
* Implements hook_init().
*/
function colorbox_init() {
// Do not load colorbox during the Drupal installation process, e.g. if part
// of installation profiles.
if (!drupal_installation_attempted()) {
_colorbox_doheader();
}
}
/**
* Implements hook_views_api().
*/
function colorbox_views_api() {
return array(
'api' => 2,
'api' => 3,
'path' => drupal_get_path('module', 'colorbox') . '/views',
);
}
/**
* Implements hook_libraries_info().
* Implements hook_library_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) v([0-9\.a-z]+)@',
'lines' => 5,
),
'files' => array(
'js' => array(
'jquery.colorbox-min.js',
),
function colorbox_library_info() {
$libraries = array();
$base = drupal_get_path('module', 'colorbox') . '/js/colorbox';
$libraries['colorbox.source'] = array(
'title' => 'Colorbox plugin',
'website' => 'http://www.jacklmoore.com/colorbox',
'version' => '1.4.27',
'js' => array(
$base . '/jquery.colorbox.js' => array(),
),
'variants' => array(
'minified' => array(
'files' => array(
'js' => array(
'jquery.colorbox-min.js',
),
),
),
'source' => array(
'files' => array(
'js' => array(
'jquery.colorbox.js',
),
),
),
);
$libraries['colorbox.minified'] = array(
'title' => 'Colorbox plugin ',
'website' => 'http://www.jacklmoore.com/colorbox',
'version' => '1.4.27',
'js' => array(
$base . '/jquery.colorbox-min.js' => array(),
),
);
return $libraries;
}
......@@ -115,13 +91,10 @@ function colorbox_libraries_info() {
function colorbox_menu() {
$items = array();
$items['admin/config/media/colorbox'] = array(
$items['colorbox_settings'] = array(
'title' => 'Colorbox',
'description' => 'Adjust Colorbox settings.',
'file' => 'colorbox.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('colorbox_admin_settings'),
'access arguments' => array('administer site configuration'),
'route_name' => 'colorbox_settings',
);
return $items;
......@@ -140,332 +113,22 @@ function _colorbox_active() {
return FALSE;
}
$config = config('colorbox.settings');
$current_path = current_path();
// Code from the block_list funtion in block.module.
$path = drupal_get_path_alias($_GET['q']);
$colorbox_pages = variable_get('colorbox_pages', "admin*\nimagebrowser*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit\nprint/*\nprintpdf/*\nsystem/ajax\nsystem/ajax/*");
$path = Drupal::service('path.alias_manager.cached')->getPathAlias($current_path);
$colorbox_pages = $config->get('colorbox_pages');
// Compare with the internal and path alias (if any).
$page_match = drupal_match_path($path, $colorbox_pages);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $colorbox_pages);
if ($path != $current_path) {
$page_match = $page_match || drupal_match_path($current_path, $colorbox_pages);
}
$page_match = variable_get('colorbox_visibility', 0) == 0 ? !$page_match : $page_match;
$page_match = $config->get('advanced.visibility') == 0 ? !$page_match : $page_match;
return $page_match;
}
/**
* Loads the various js and css files.
*/
function _colorbox_doheader() {
static $already_added = FALSE;
if ($already_added) {
return; // Don't add the JavaScript and CSS multiple times.
}
if (!_colorbox_active()) {
return; // Don't add the JavaScript and CSS on specified paths.
}
// Insert options and translated strings as javascript settings.
if (variable_get('colorbox_custom_settings_activate', 0)) {
$js_settings = array(
'transition' => variable_get('colorbox_transition_type', 'elastic'),
'speed' => variable_get('colorbox_transition_speed', 350),
'opacity' => variable_get('colorbox_opacity', '0.85'),
'slideshow' => variable_get('colorbox_slideshow', 0) ? TRUE : FALSE,
'slideshowAuto' => variable_get('colorbox_slideshowauto', 1) ? TRUE : FALSE,
'slideshowSpeed' => variable_get('colorbox_slideshowspeed', 2500),
'slideshowStart' => variable_get('colorbox_text_start', 'start slideshow'),
'slideshowStop' => variable_get('colorbox_text_stop', 'stop slideshow'),
'current' => variable_get('colorbox_text_current', '{current} of {total}'),
'previous' => variable_get('colorbox_text_previous', '« Prev'),
'next' => variable_get('colorbox_text_next', 'Next »'),
'close' => variable_get('colorbox_text_close', 'Close'),
'overlayClose' => variable_get('colorbox_overlayclose', 1) ? TRUE : FALSE,
'maxWidth' => variable_get('colorbox_maxwidth', '98%'),
'maxHeight' => variable_get('colorbox_maxheight', '98%'),
'initialWidth' => variable_get('colorbox_initialwidth', '300'),
'initialHeight' => variable_get('colorbox_initialheight', '250'),
'fixed' => variable_get('colorbox_fixed', 1) ? TRUE : FALSE,
'scrolling' => variable_get('colorbox_scrolling', 1) ? TRUE : FALSE,
'mobiledetect' => variable_get('colorbox_mobile_detect', 1) ? TRUE : FALSE,
'mobiledevicewidth' => variable_get('colorbox_mobile_device_width', '480px'),
);
}
else {
$js_settings = array(
'opacity' => '0.85',
'current' => t('{current} of {total}'),
'previous' => t('« Prev'),
'next' => t('Next »'),
'close' => t('Close'),
'maxWidth' => '98%',
'maxHeight' => '98%',
'fixed' => TRUE,
'mobiledetect' => variable_get('colorbox_mobile_detect', 1) ? TRUE : FALSE,
'mobiledevicewidth' => variable_get('colorbox_mobile_device_width', '480px'),
);
}
$path = drupal_get_path('module', 'colorbox');
$style = variable_get('colorbox_style', 'default');
// Give other modules the possibility to override Colorbox settings and style.
$data = &$js_settings;
drupal_alter('colorbox_settings', $data, $style);
drupal_add_js(array('colorbox' => $js_settings), array('type' => 'setting', 'scope' => JS_DEFAULT));
// Add and initialise the Colorbox plugin.
$variant = variable_get('colorbox_compression_type', 'minified');
libraries_load('colorbox', $variant);
drupal_add_js($path . '/js/colorbox.js');
// Add JS and CSS based on selected style.
switch ($style) {
case 'none':
break;
case 'default':
case 'plain':
case 'stockholmsyndrome':
drupal_add_css($path . '/styles/' . $style . '/colorbox_style.css');
drupal_add_js($path . '/styles/' . $style . '/colorbox_style.js');
break;
default:
drupal_add_css($style . '/colorbox.css');
}
if (variable_get('colorbox_load', 0)) {
drupal_add_js($path . '/js/colorbox_load.js');
}
if (variable_get('colorbox_inline', 0)) {
drupal_add_js($path . '/js/colorbox_inline.js');
}
$already_added = TRUE;
}
/**
* Implements hook_field_formatter_info().
*/
function colorbox_field_formatter_info() {
return array(
'colorbox' => array(
'label' => t('Colorbox'),
'field types' => array('image'),
'settings' => array(
'colorbox_node_style' => '',
'colorbox_image_style' => '',
'colorbox_gallery' => 'post',
'colorbox_gallery_custom' => '',
'colorbox_caption' => 'auto',
'colorbox_caption_custom' => '',
'colorbox_multivalue_index' => NULL,
),
),
);
}
/**
* Implements hook_field_formatter_settings_form().
*/
function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];