Commit f3bc65ec authored by grisendo's avatar grisendo
Browse files

Adapted to 8.x-apha8

parent a860c299
......@@ -44,13 +44,6 @@ function colorbox_requirements($phase) {
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function colorbox_uninstall() {
db_delete('variable')->condition('name', db_like('colorbox_') . '%', 'LIKE')->execute();
}
/**
* Delete the unused colorbox_login_form variable.
*/
......
......@@ -37,13 +37,9 @@ function colorbox_theme() {
'colorbox_image_formatter' => array(
'variables' => array(
'item' => NULL,
'entity_type' => NULL,
'image' => NULL,
'entity' => NULL,
'node' => NULL, // Left for legacy support.
'field' => array(),
'path' => drupal_get_path('module', 'colorbox') . '/templates',
'display_settings' => array(),
'settings' => NULL,
),
'file' => 'colorbox.theme.inc',
),
......@@ -95,10 +91,10 @@ function colorbox_libraries_info() {
function colorbox_menu() {
$items = array();
$items['colorbox_settings'] = array(
$items['colorbox.settings'] = array(
'title' => 'Colorbox',
'description' => 'Adjust Colorbox settings.',
'route_name' => 'colorbox_settings',
'route_name' => 'colorbox.settings',
);
return $items;
......@@ -117,7 +113,7 @@ function _colorbox_active() {
return FALSE;
}
$config = config('colorbox.settings');
$config = \Drupal::config('colorbox.settings');
$current_path = current_path();
// Code from the block_list funtion in block.module.
......
colorbox_settings:
pattern: '/admin/config/media/colorbox'
colorbox.settings:
path: '/admin/config/media/colorbox'
defaults:
_form: 'Drupal\colorbox\Form\ColorboxSettingsForm'
_title: 'Colorbox'
_form: '\Drupal\colorbox\Form\ColorboxSettingsForm'
requirements:
_permission: 'administer site configuration'
......@@ -17,36 +17,32 @@
* @ingroup themeable
*/
function theme_colorbox_image_formatter($variables) {
$item = $variables['item'];
$entity_type = $variables['entity_type'];
$entity = $variables['entity'];
$field = $variables['field'];
$settings = $variables['display_settings'];
$image = array(
'uri' => $item['entity']->getFileUri(),
'alt' => isset($item['alt']) ? $item['alt'] : '',
'title' => isset($item['title']) ? $item['title'] : '',
'style_name' => $settings['colorbox_node_style'],
'uri' => $variables['image']->entity->getFileUri(),
'alt' => $variables['image']->alt,
'title' => $variables['image']->title,
'style_name' => $variables['settings']['colorbox_node_style'],
);
if (isset($item['width']) && isset($item['height'])) {
$image['width'] = $item['width'];
$image['height'] = $item['height'];
}
//FFFif (isset($item['width']) && isset($item['height'])) {
//FFF$image['width'] = $item['width'];
//FFF$image['height'] = $item['height'];
//FFF}
$entity_title = $entity->label();
$entity_title = $variables['image']->getEntity()->label();
$entity_type = $variables['entity']->entityType();
switch ($settings['colorbox_caption']) {
switch ($variables['settings']['colorbox_caption']) {
case 'auto':
// If the title is empty use alt or the entity title in that order.
if (!empty($image['title'])) {
$caption = $image['title'];
if ($variables['image']->title) {
$caption = $variables['image']->title;
}
elseif (!empty($image['alt'])) {
$caption = $image['alt'];
elseif ($variables['image']->alt) {
$caption = $variables['image']->alt;
}
elseif (!empty($entity_title)) {
elseif ($entity_title) {
$caption = $entity_title;
}
else {
......@@ -54,17 +50,23 @@ function theme_colorbox_image_formatter($variables) {
}
break;
case 'title':
$caption = $image['title'];
$caption = $variables['image']->title;
break;
case 'alt':
$caption = $image['alt'];
$caption = $variables['image']->alt;
break;
case 'node_title':
$caption = $entity_title;
break;
case 'custom':
$token_service = \Drupal::token();
$caption = $token_service->replace($settings['colorbox_caption_custom'], array($entity_type => $entity, 'file' => (object) $item), array('clear' => TRUE));
$caption = $token_service->replace(
$variables['settings']['colorbox_caption_custom'],
array(
$entity_type => $variables['entity'],
'file' => $variables['image']),
array('clear' => TRUE)
);
break;
default:
$caption = '';
......@@ -78,10 +80,11 @@ function theme_colorbox_image_formatter($variables) {
}
// Build the gallery id.
$id = $entity->id();
$bundle = $entity->bundle();
$entity_id = !empty($id) ? $entity_type . '-' . $id : 'entity-id';
switch ($settings['colorbox_gallery']) {
$id = $variables['entity']->id();
$entity_bundle = $variables['entity']->getType();
$entity_id = !empty($id) ? $entity_bundle . '-' . $id : 'entity-id';
$field = $variables['image']->getParent()->getName();
switch ($variables['settings']['colorbox_gallery']) {
case 'post':
$gallery_id = 'gallery-' . $entity_id;
break;
......@@ -89,20 +92,28 @@ function theme_colorbox_image_formatter($variables) {
$gallery_id = 'gallery-all';
break;
case 'field_post':
$gallery_id = 'gallery-' . $entity_id . '-' . $field->getFieldName();
$gallery_id = 'gallery-' . $entity_id . '-' . $field;
break;
case 'field_page':
$gallery_id = 'gallery-' . $field->getFieldName();
$gallery_id = 'gallery-' . $field;
break;
case 'custom':
$gallery_id = $settings['colorbox_gallery_custom'];
$token_service = \Drupal::token();
$gallery_id = $token_service->replace(
$variables['settings']['colorbox_gallery_custom'],
array(
$entity_type => $variables['entity'],
'file' => $variables['image']),
array('clear' => TRUE)
);
break;
default:
$gallery_id = '';
}
if ($style_name = $settings['colorbox_image_style']) {
$path = image_style_url($style_name, $image['uri']);
if ($style_name = $variables['settings']['colorbox_image_style']) {
$style = entity_load('image_style', $style_name);
$path = $style->buildUrl($image['uri']);
}
else {
$path = file_create_url($image['uri']);
......@@ -150,7 +161,7 @@ function theme_colorbox_imagefield($variables) {
}
/**
* Preprocess variables for the colorbox-insert-image.tpl.php file.
* Preprocess variables for the colorbox-insert-image.html.twig file.
*/
function template_preprocess_colorbox_insert_image(&$variables) {
$class = array();
......
......@@ -42,7 +42,7 @@ class ColorboxSubscriber implements EventSubscriberInterface {
* The Event to process.
*/
public function colorboxLoadLibrary(GetResponseEvent $event) {
$config = config('colorbox.settings');
$config = \Drupal::config('colorbox.settings');
if (!drupal_installation_attempted()) {
static $already_added = FALSE;
if ($already_added) {
......@@ -100,12 +100,29 @@ class ColorboxSubscriber implements EventSubscriberInterface {
$data = &$js_settings;
$this->module_handler->alter('colorbox_settings', $data, $style);
drupal_add_js(array('colorbox' => $js_settings), array('type' => 'setting', 'scope' => JS_DEFAULT));
$settings = array(
'#attached' => array(
'js' => array(
array(
'data' => array('colorbox' => $js_settings),
'type' => 'setting',
),
),
),
);
drupal_render($settings);
// Add and initialise the Colorbox plugin.
$variant = $config->get('advanced.compression_type');
libraries_load('colorbox', $variant);
drupal_add_js($path . '/js/colorbox.js');
$colorbox = array(
'#attached' => array(
'js' => array(
$path . '/js/colorbox.js' => array(),
),
),
);
drupal_render($colorbox);
// Add JS and CSS based on selected style.
switch ($style) {
......@@ -114,19 +131,49 @@ class ColorboxSubscriber implements EventSubscriberInterface {
case 'default':
case 'plain':
case 'stockholmsyndrome':
drupal_add_css($path . '/styles/' . $style . '/colorbox_style.css');
drupal_add_js($path . '/styles/' . $style . '/colorbox_style.js');
$style_render = array(
'#attached' => array(
'css' => array(
$path . '/styles/' . $style . '/colorbox_style.css' => array(),
),
'js' => array(
$path . '/styles/' . $style . '/colorbox_style.js' => array(),
),
),
);
drupal_render($style_render);
break;
default:
drupal_add_css($style . '/colorbox.css');
$style_render = array(
'#attached' => array(
'css' => array(
$path . '/styles/' . $style . '/colorbox.css' => array(),
),
),
);
drupal_render($style_render);
}
if ($config->get('extra.load', 0)) {
drupal_add_js($path . '/js/colorbox_load.js');
$load = array(
'#attached' => array(
'js' => array(
$path . '/js/colorbox_load.js' => array(),
),
),
);
drupal_render($load);
}
if ($config->get('extra.inline', 0)) {
drupal_add_js($path . '/js/colorbox_inline.js');
$inline = array(
'#attached' => array(
'js' => array(
$path . '/js/colorbox_inline.js' => array(),
),
),
);
drupal_render($inline);
}
$already_added = TRUE;
......
......@@ -7,14 +7,14 @@
namespace Drupal\colorbox\Form;
use Drupal\system\SystemConfigFormBase;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Config\ConfigFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* General configuration form for controlling the colorbox behaviour..
*/
class ColorboxSettingsForm extends SystemConfigFormBase {
class ColorboxSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
......@@ -31,7 +31,14 @@ class ColorboxSettingsForm extends SystemConfigFormBase {
// Get all settings
$config = $this->configFactory->get('colorbox.settings');
drupal_add_js(drupal_get_path('module', 'colorbox') . '/js/colorbox_admin_settings.js', array('preprocess' => FALSE));
$conf_js = array(
'#attached' => array(
'js' => array(
drupal_get_path('module', 'colorbox') . '/js/colorbox_admin_settings.js' => array('preprocess' => FALSE),
),
),
);
drupal_render($conf_js);
$library = libraries_detect('colorbox');
......
......@@ -2,15 +2,15 @@
/**
* @file
* Contains \Drupal\colorbox\Plugin\field\formatter\ColorboxFormatter.
* Contains \Drupal\colorbox\Plugin\Field\FieldFormatter\ColorboxFormatter.
*/
namespace Drupal\colorbox\Plugin\field\formatter;
namespace Drupal\colorbox\Plugin\Field\FieldFormatter;
use Drupal\field\Annotation\FieldFormatter;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
/**
* Plugin implementation of the 'colorbox' formatter.
......@@ -76,15 +76,20 @@ class ColorboxFormatter extends FormatterBase {
);
$element['colorbox_gallery_custom'] = array(
'#title' => t('Custom gallery'),
'#type' => 'machine_name',
'#maxlength' => 32,
'#type' => 'textfield',
'#default_value' => $this->getSetting('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.'),
'#description' => t('All images on a page with the same gallery value (rel attribute) will be grouped together.'),
'#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'),
),
),
);
$element['colorbox_token_gallery'] = 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_gallery]"]' => array('value' => 'custom'),
......@@ -117,7 +122,7 @@ class ColorboxFormatter extends FormatterBase {
),
),
);
$element['colorbox_token'] = array(
$element['colorbox_token_caption'] = 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>',
......@@ -190,20 +195,19 @@ class ColorboxFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
public function viewElements(FieldItemListInterface $items) {
$element = array();
$index = $this->getSetting('colorbox_multivalue_index');
$entity = $items->getEntity();
$settings = $this->getSettings();
foreach ($items as $delta => $item) {
if ($index === NULL || $index === '' || $index === $delta) {
$element[$delta] = array(
'#theme' => 'colorbox_image_formatter',
'#item' => $item,
'#entity_type' => $entity->getType(),
'#image' => $item,
'#entity' => $entity,
'#node' => $entity, // Left for legacy support.
'#field' => $this->fieldDefinition,
'#display_settings' => $this->getSettings(),
'#settings' => $settings,
);
}
}
......
......@@ -10,6 +10,7 @@ namespace Drupal\colorbox\Plugin\views\field;
use Drupal\Component\Annotation\PluginID;
use Drupal\Core\Annotation\Translation;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
/**
* A handler to provide a field that is completely custom by the administrator.
......@@ -150,11 +151,18 @@ If you would like to have the characters %5B and %5D please use the html entity
/**
* Render the trigger field and its linked popup information.
*/
function render($values) {
function render(ResultRow $values) {
$config = config('colorbox.settings');
// Load the necessary js file for Colorbox activation.
if (_colorbox_active() && !$config->get('extra.inline')) {
drupal_add_js(drupal_get_path('module', 'colorbox') . '/js/colorbox_inline.js');
$conf_js = array(
'#attached' => array(
'js' => array(
drupal_get_path('module', 'colorbox') . '/js/colorbox_inline.js' => array(),
),
),
);
drupal_render($conf_js);
}
// We need to have multiple unique IDs, one for each record.
......
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