Commit 0e5d4c53 authored by frjo's avatar frjo
Browse files

Some very unfinshed Drupal 8 code. Just for the history.

parent 6507855e
......@@ -11,7 +11,10 @@
function colorbox_admin_settings() {
drupal_add_js(drupal_get_path('module', 'colorbox') . '/js/colorbox_admin_settings.js', array('preprocess' => FALSE));
$library = libraries_detect('colorbox');
//$library = libraries_detect('colorbox');
$library = array(
'library path' => '',
);
if (module_exists('insert')) {
$form['colorbox_insert_module'] = array(
......
name: Colorbox
description: 'A light-weight, customizable lightbox plugin for jQuery 1.4.3+.'
package: Media
core: 8.x
configure: admin/config/media/colorbox
#dependencies:
# - libraries
......@@ -8,40 +8,40 @@
/**
* Implements hook_requirements().
*/
function colorbox_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
$t = get_t();
$library = libraries_detect('colorbox');
if (empty($library['installed'])) {
$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 the !colorbox, extract the archive and place the colorbox directory in the %path directory on your server.', array('!colorbox' => l($t('Colorbox plugin'), $library['download url']), '%path' => 'sites/all/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 !colorbox and replace the old version located in the %path directory on your server.', array('!colorbox' => l($t('Colorbox plugin'), $library['download url']), '%path' => $library['library path'])),
);
}
}
return $requirements;
}
// function colorbox_requirements($phase) {
// $requirements = array();
//
// if ($phase == 'runtime') {
// $t = get_t();
// $library = libraries_detect('colorbox');
//
// if (empty($library['installed'])) {
// $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 the !colorbox, extract the archive and place the colorbox directory in the %path directory on your server.', array('!colorbox' => l($t('Colorbox plugin'), $library['download url']), '%path' => 'sites/all/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 !colorbox and replace the old version located in the %path directory on your server.', array('!colorbox' => l($t('Colorbox plugin'), $library['download url']), '%path' => $library['library path'])),
// );
// }
// }
//
// return $requirements;
// }
/**
* Implements hook_uninstall().
......
......@@ -77,7 +77,7 @@ function colorbox_libraries_info() {
$libraries['colorbox'] = array(
'name' => 'Colorbox plugin',
'vendor url' => 'http://www.jacklmoore.com/colorbox',
'download 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' => '@ColorBox v([0-9\.a-z]+)@',
......@@ -141,12 +141,12 @@ function _colorbox_active() {
}
// Code from the block_list funtion in block.module.
$path = drupal_get_path_alias($_GET['q']);
$path = drupal_container()->get('path.alias_manager.cached')->getPathAlias(current_path());
$colorbox_pages = variable_get('colorbox_pages', "admin*\nimagebrowser*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit\nprint/*\nprintpdf/*\nsystem/ajax\nsystem/ajax/*");
// 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;
......@@ -213,7 +213,7 @@ function _colorbox_doheader() {
// Add and initialise the Colorbox plugin.
$variant = variable_get('colorbox_compression_type', 'minified');
libraries_load('colorbox', $variant);
// libraries_load('colorbox', $variant);
drupal_add_js($path . '/js/colorbox.js');
// Add JS and CSS based on selected style.
......@@ -241,226 +241,226 @@ function _colorbox_doheader() {
$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'];
$image_styles = image_style_options(FALSE);
$image_styles_hide = $image_styles;
$image_styles_hide['hide'] = t('Hide (do not display image)');
$element['colorbox_node_style'] = array(
'#title' => t('Content image style'),
'#type' => 'select',
'#default_value' => $settings['colorbox_node_style'],
'#empty_option' => t('None (original image)'),
'#options' => $image_styles_hide,
'#description' => t('Image style to use in the content.'),
);
$element['colorbox_image_style'] = array(
'#title' => t('Colorbox image style'),
'#type' => 'select',
'#default_value' => $settings['colorbox_image_style'],
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
'#description' => t('Image style to use in the Colorbox.'),
);
$gallery = array(
'post' => t('Per post gallery'),
'page' => t('Per page gallery'),
'field_post' => t('Per field in post gallery'),
'field_page' => t('Per field in page gallery'),
'custom' => t('Custom'),
'none' => t('No gallery'),
);
$element['colorbox_gallery'] = array(
'#title' => t('Gallery (image grouping)'),
'#type' => 'select',
'#default_value' => $settings['colorbox_gallery'],
'#options' => $gallery,
'#description' => t('How Colorbox should group the image galleries.'),
);
$element['colorbox_gallery_custom'] = array(
'#title' => t('Custom gallery'),
'#type' => 'machine_name',
'#maxlength' => 32,
'#default_value' => $settings['colorbox_gallery_custom'],
'#description' => t('All images on a page with the same gallery value (rel attribute) will be grouped together. It must only contain lowercase letters, numbers, and underscores.'),
'#required' => FALSE,
'#machine_name' => array(
'exists' => 'colorbox_gallery_exists',
'error' => t('The custom gallery field must only contain lowercase letters, numbers, and underscores.'),
),
'#states' => array(
'visible' => array(
':input[name$="[settings_edit_form][settings][colorbox_gallery]"]' => array('value' => 'custom'),
),
),
);
$caption = array(
'auto' => t('Automatic'),
'title' => t('Title text'),
'alt' => t('Alt text'),
'node_title' => t('Content title'),
'custom' => t('Custom (with tokens)'),
'none' => t('None'),
);
$element['colorbox_caption'] = array(
'#title' => t('Caption'),
'#type' => 'select',
'#default_value' => $settings['colorbox_caption'],
'#options' => $caption,
'#description' => t('Automatic will use the first none empty value of the title, the alt text and the content title.'),
);
$element['colorbox_caption_custom'] = array(
'#title' => t('Custom caption'),
'#type' => 'textfield',
'#default_value' => $settings['colorbox_caption_custom'],
'#states' => array(
'visible' => array(
':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array('value' => 'custom'),
),
),
);
// Allow users to hide or set a custom recursion limit.
// The module token_tweaks sets a global recursion limit that can not be bypassed.
if (module_exists('token') && $recursion_limit = min(variable_get('token_tree_recursion_limit', 3), variable_get('colorbox_token_recursion_limit', 3))) {
$element['colorbox_token'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#theme' => 'token_tree',
'#token_types' => array($instance['entity_type'], 'file'),
'#recursion_limit' => $recursion_limit,
'#dialog' => TRUE,
'#states' => array(
'visible' => array(
':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array('value' => 'custom'),
),
),
);
}
else {
$element['colorbox_token'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#description' => '<strong class="error">' . t('For token support the <a href="@token_url">token module</a> must be installed.', array('@token_url' => 'http://drupal.org/project/token')) . '</strong>',
'#states' => array(
'visible' => array(
':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array('value' => 'custom'),
),
),
);
}
return $element;
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function colorbox_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$summary = array();
$image_styles = image_style_options(FALSE);
// Unset possible 'No defined styles' option.
unset($image_styles['']);
// Styles could be lost because of enabled/disabled modules that defines
// their styles in code.
if (isset($image_styles[$settings['colorbox_node_style']])) {
$summary[] = t('Content image style: @style', array('@style' => $image_styles[$settings['colorbox_node_style']]));
}
elseif ($settings['colorbox_node_style'] == 'hide') {
$summary[] = t('Content image style: Hide');
}
else {
$summary[] = t('Content image style: Original image');
}
if (isset($image_styles[$settings['colorbox_image_style']])) {
$summary[] = t('Colorbox image style: @style', array('@style' => $image_styles[$settings['colorbox_image_style']]));
}
else {
$summary[] = t('Colorbox image style: Original image');
}
$gallery = array(
'post' => t('Per post gallery'),
'page' => t('Per page gallery'),
'field_post' => t('Per field in post gallery'),
'field_page' => t('Per field in page gallery'),
'custom' => t('Custom'),
'none' => t('No gallery'),
);
if (isset($settings['colorbox_gallery'])) {
$summary[] = t('Colorbox gallery type: @type', array('@type' => $gallery[$settings['colorbox_gallery']])) . ($settings['colorbox_gallery'] == 'custom' ? ' (' . $settings['colorbox_gallery_custom'] . ')' : '');
}
$caption = array(
'auto' => t('Automatic'),
'title' => t('Title text'),
'alt' => t('Alt text'),
'node_title' => t('Content title'),
'custom' => t('Custom (with tokens)'),
'none' => t('None'),
);
if (isset($settings['colorbox_caption'])) {
$summary[] = t('Colorbox caption: @type', array('@type' => $caption[$settings['colorbox_caption']]));
}
return implode('<br />', $summary);
}
/**
* Implements hook_field_formatter_view().
*/
function colorbox_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$index = $display['settings']['colorbox_multivalue_index'];
foreach ($items as $delta => $item) {
if ($index === NULL || $index === $delta) {
$element[$delta] = array(
'#theme' => 'colorbox_image_formatter',
'#item' => $item,
'#entity_type' => $entity_type,
'#entity' => $entity,
'#node' => $entity, // Left for legacy support.
'#field' => $field,
'#display_settings' => $display['settings'],
);
}
}
return $element;
}
// /**
// * 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'];
//
// $image_styles = image_style_options(FALSE);
// $image_styles_hide = $image_styles;
// $image_styles_hide['hide'] = t('Hide (do not display image)');
// $element['colorbox_node_style'] = array(
// '#title' => t('Content image style'),
// '#type' => 'select',
// '#default_value' => $settings['colorbox_node_style'],
// '#empty_option' => t('None (original image)'),
// '#options' => $image_styles_hide,
// '#description' => t('Image style to use in the content.'),
// );
// $element['colorbox_image_style'] = array(
// '#title' => t('Colorbox image style'),
// '#type' => 'select',
// '#default_value' => $settings['colorbox_image_style'],
// '#empty_option' => t('None (original image)'),
// '#options' => $image_styles,
// '#description' => t('Image style to use in the Colorbox.'),
// );
//
// $gallery = array(
// 'post' => t('Per post gallery'),
// 'page' => t('Per page gallery'),
// 'field_post' => t('Per field in post gallery'),
// 'field_page' => t('Per field in page gallery'),
// 'custom' => t('Custom'),
// 'none' => t('No gallery'),
// );
// $element['colorbox_gallery'] = array(
// '#title' => t('Gallery (image grouping)'),
// '#type' => 'select',
// '#default_value' => $settings['colorbox_gallery'],
// '#options' => $gallery,
// '#description' => t('How Colorbox should group the image galleries.'),
// );
// $element['colorbox_gallery_custom'] = array(
// '#title' => t('Custom gallery'),
// '#type' => 'machine_name',
// '#maxlength' => 32,
// '#default_value' => $settings['colorbox_gallery_custom'],
// '#description' => t('All images on a page with the same gallery value (rel attribute) will be grouped together. It must only contain lowercase letters, numbers, and underscores.'),
// '#required' => FALSE,
// '#machine_name' => array(
// 'exists' => 'colorbox_gallery_exists',
// 'error' => t('The custom gallery field must only contain lowercase letters, numbers, and underscores.'),
// ),
// '#states' => array(
// 'visible' => array(
// ':input[name$="[settings_edit_form][settings][colorbox_gallery]"]' => array('value' => 'custom'),
// ),
// ),
// );
//
// $caption = array(
// 'auto' => t('Automatic'),
// 'title' => t('Title text'),
// 'alt' => t('Alt text'),
// 'node_title' => t('Content title'),
// 'custom' => t('Custom (with tokens)'),
// 'none' => t('None'),
// );
// $element['colorbox_caption'] = array(
// '#title' => t('Caption'),
// '#type' => 'select',
// '#default_value' => $settings['colorbox_caption'],
// '#options' => $caption,
// '#description' => t('Automatic will use the first none empty value of the title, the alt text and the content title.'),
// );
// $element['colorbox_caption_custom'] = array(
// '#title' => t('Custom caption'),
// '#type' => 'textfield',
// '#default_value' => $settings['colorbox_caption_custom'],
// '#states' => array(
// 'visible' => array(
// ':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array('value' => 'custom'),
// ),
// ),
// );
// // Allow users to hide or set a custom recursion limit.
// // The module token_tweaks sets a global recursion limit that can not be bypassed.
// if (module_exists('token') && $recursion_limit = min(variable_get('token_tree_recursion_limit', 3), variable_get('colorbox_token_recursion_limit', 3))) {
// $element['colorbox_token'] = array(
// '#type' => 'fieldset',
// '#title' => t('Replacement patterns'),
// '#theme' => 'token_tree',
// '#token_types' => array($instance['entity_type'], 'file'),
// '#recursion_limit' => $recursion_limit,
// '#dialog' => TRUE,
// '#states' => array(
// 'visible' => array(
// ':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array('value' => 'custom'),
// ),
// ),
// );
// }
// else {
// $element['colorbox_token'] = array(
// '#type' => 'fieldset',
// '#title' => t('Replacement patterns'),
// '#description' => '<strong class="error">' . t('For token support the <a href="@token_url">token module</a> must be installed.', array('@token_url' => 'http://drupal.org/project/token')) . '</strong>',
// '#states' => array(
// 'visible' => array(
// ':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array('value' => 'custom'),
// ),
// ),
// );
// }
//
// return $element;
// }
//
// /**
// * Implements hook_field_formatter_settings_summary().
// */
// function colorbox_field_formatter_settings_summary($field, $instance, $view_mode) {
// $display = $instance['display'][$view_mode];
// $settings = $display['settings'];
//
// $summary = array();
//
// $image_styles = image_style_options(FALSE);
// // Unset possible 'No defined styles' option.
// unset($image_styles['']);
// // Styles could be lost because of enabled/disabled modules that defines
// // their styles in code.
// if (isset($image_styles[$settings['colorbox_node_style']])) {
// $summary[] = t('Content image style: @style', array('@style' => $image_styles[$settings['colorbox_node_style']]));
// }
// elseif ($settings['colorbox_node_style'] == 'hide') {
// $summary[] = t('Content image style: Hide');
// }
// else {
// $summary[] = t('Content image style: Original image');
// }
//
// if (isset($image_styles[$settings['colorbox_image_style']])) {
// $summary[] = t('Colorbox image style: @style', array('@style' => $image_styles[$settings['colorbox_image_style']]));
// }
// else {
// $summary[] = t('Colorbox image style: Original image');
// }
//
// $gallery = array(
// 'post' => t('Per post gallery'),
// 'page' => t('Per page gallery'),
// 'field_post' => t('Per field in post gallery'),
// 'field_page' => t('Per field in page gallery'),
// 'custom' => t('Custom'),
// 'none' => t('No gallery'),
// );
// if (isset($settings['colorbox_gallery'])) {
// $summary[] = t('Colorbox gallery type: @type', array('@type' => $gallery[$settings['colorbox_gallery']])) . ($settings['colorbox_gallery'] == 'custom' ? ' (' . $settings['colorbox_gallery_custom'] . ')' : '');
// }
//
// $caption = array(
// 'auto' => t('Automatic'),
// 'title' => t('Title text'),
// 'alt' => t('Alt text'),
// 'node_title' => t('Content title'),
// 'custom' => t('Custom (with tokens)'),
// 'none' => t('None'),
// );
// if (isset($settings['colorbox_caption'])) {
// $summary[] = t('Colorbox caption: @type', array('@type' => $caption[$settings['colorbox_caption']]));
// }
//
// return implode('<br />', $summary);
// }
//
// /**
// * Implements hook_field_formatter_view().
// */
// function colorbox_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
// $element = array();
// $index = $display['settings']['colorbox_multivalue_index'];
//
// foreach ($items as $delta => $item) {
// if ($index === NULL || $index === $delta) {
// $element[$delta] = array(
// '#theme' => 'colorbox_image_formatter',
// '#item' => $item,
// '#entity_type' => $entity_type,
// '#entity' => $entity,
// '#node' => $entity, // Left for legacy support.
// '#field' => $field,
// '#display_settings' => $display['settings'],
// );
// }
// }
//
// return $element;
// }
/**
* Implements hook_insert_styles().
......
<?php
/**
* @file
* Contains \Drupal\colorbox\Plugin\field\formatter\ColorboxFormatter.
*/
namespace Drupal\image\Plugin\field\formatter;
use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
use Drupal\Core\Entity\EntityInterface;
/**
* Plugin implementation of the 'colorbox' formatter.
*
* @Plugin(
* id = "colorbox",
* module = "colorbox",
* label = @Translation("Colorbox"),
* field_types = {
* "image"
* },
* settings = {
* "colorbox_node_style" = "",
* "colorbox_image_style" = "",
* "colorbox_gallery" = "post",
* "colorbox_gallery_custom" = "",
* "colorbox_caption" = "auto",
* "colorbox_caption_custom" = "",
* "colorbox_multivalue_index" = NULL,
* }
* )
*/
class ColorboxFormatter extends FormatterBase {
/**
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
*/
public function settingsForm(array $form, array &$form_state) {
$image_styles = image_style_options(FALSE);
$image_styles_hide = $image_styles;
$image_styles_hide['hide'] = t('Hide (do not display image)');
$element['colorbox_node_style'] = array(
'#title' => t('Content image style'),
'#type' => 'select',