Commit c96838f4 authored by cebasqueira's avatar cebasqueira Committed by frjo

Issue #2832152 by cebasqueira: Colorbox Drupal code standards not followed

parent 883b4203
......@@ -38,7 +38,7 @@ function template_preprocess_colorbox_formatter(&$variables) {
$entity_bundle = $entity->bundle();
switch ($settings['colorbox_caption']) {
case 'auto':
case 'auto':
// If the title is empty use alt or the entity title in that order.
if (!empty($item->title)) {
$caption = $item->title;
......@@ -53,24 +53,30 @@ function template_preprocess_colorbox_formatter(&$variables) {
$caption = '';
}
break;
case 'title':
$caption = $item->title;
break;
case 'alt':
$caption = $item->alt;
break;
case 'entity_title':
$caption = $entity_title;
break;
case 'custom':
$token_service = \Drupal::token();
$caption = $token_service->replace($settings['colorbox_caption_custom'], array($entity_type => $entity, 'file' => $item), array('clear' => TRUE));
break;
default:
$caption = '';
}
// Shorten the caption for the example styles or when caption shortening is active.
// Shorten the caption for the example styles or when caption
// shortening is active.
$config = \Drupal::config('colorbox.settings');
$colorbox_style = $config->get('colorbox_style');
$trim_length = $config->get('colorbox_caption_trim_length');
......@@ -87,26 +93,33 @@ function template_preprocess_colorbox_formatter(&$variables) {
case 'post':
$gallery_id = 'gallery-' . $entity_id;
break;
case 'page':
$gallery_id = 'gallery-all';
break;
case 'field_post':
$gallery_id = 'gallery-' . $entity_id . '-' . $field_name;
break;
case 'field_page':
$gallery_id = 'gallery-' . $field_name;
break;
case 'custom':
$token_service = \Drupal::token();
$gallery_id = $token_service->replace($settings['colorbox_gallery_custom'], array($entity_type => $entity, 'file' => $item), array('clear' => TRUE));
break;
default:
$gallery_id = '';
}
// If gallery id is not empty add unique per-request token to avoid images being added manually to galleries.
// If gallery id is not empty add unique per-request token to avoid
// images being added manually to galleries.
if (!empty($gallery_id) && $config->get('advanced.unique_token')) {
// Check if gallery token has already been set, we need to reuse the token for the whole request.
// Check if gallery token has already been set, we need to reuse
// the token for the whole request.
if (is_null($gallery_token)) {
// We use a short token since randomness is not critical.
$gallery_token = Crypt::randomBytesBase64(8);
......@@ -154,18 +167,18 @@ function template_preprocess_colorbox_formatter(&$variables) {
$variables['url'] = file_create_url($image_uri);
}
// if File Entity module is enabled, load attribute values from file entity.
if(\Drupal::moduleHandler()->moduleExists('file_entity')) {
// file id of the save file.
// If File Entity module is enabled, load attribute values from file entity.
if (\Drupal::moduleHandler()->moduleExists('file_entity')) {
// File id of the save file.
$fid = $item->target_id;
// load file object
// Load file object.
$file_obj = file_load($fid);
$file_array = $file_obj->toArray();
// populate the image title
// Populate the image title.
if (!empty($file_array['field_image_title_text'][0]['value']) && empty($item->title) && $settings['colorbox_caption'] == 'title') {
$caption = $file_array['field_image_title_text'][0]['value'];
}
// populate the image alt text.
// Populate the image alt text.
if (!empty($file_array['field_image_alt_text'][0]['value']) && empty($item->alt) && $settings['colorbox_caption'] == 'alt') {
$caption = $file_array['field_image_alt_text'][0]['value'];
}
......
......@@ -2,7 +2,7 @@
/**
* @file
* drush integration for colorbox.
* Drush integration for colorbox.
*/
/**
......@@ -12,28 +12,17 @@ define('COLORBOX_DOWNLOAD_URI', 'https://github.com/jackmoore/colorbox/archive/m
define('COLORBOX_DOWNLOAD_PREFIX', 'colorbox-');
/**
* Implementation of hook_drush_command().
*
* In this hook, you specify which commands your
* drush module makes available, what it does and
* description.
*
* Notice how this structure closely resembles how
* you define menu hooks.
*
* See `drush topic docs-commands` for a list of recognized keys.
*
* @return array
* An associative array describing your command(s).
* Implements hook_drush_command().
*/
function colorbox_drush_command() {
$items = array();
// the key in the $items array is the name of the command.
// The key in the $items array is the name of the command.
$items['colorbox-plugin'] = array(
'callback' => 'drush_colorbox_plugin',
'description' => dt('Download and install the Colorbox plugin.'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap.
// No bootstrap.
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'path' => dt('Optional. A path where to install the Colorbox plugin. If omitted Drush will use the default location.'),
),
......@@ -44,16 +33,10 @@ function colorbox_drush_command() {
}
/**
* Implementation of hook_drush_help().
* Implements hook_drush_help().
*
* This function is called whenever a drush user calls
* 'drush help <name-of-your-command>'
*
* @param string $section
* A string with the help section (prepend with 'drush:')
*
* @return string
* A string with the help text for your command.
*/
function colorbox_drush_help($section) {
switch ($section) {
......@@ -84,19 +67,19 @@ function drush_colorbox_plugin() {
$olddir = getcwd();
chdir($path);
// Download the zip archive
// Download the zip archive.
if ($filepath = drush_download_file(COLORBOX_DOWNLOAD_URI)) {
$filename = basename($filepath);
$dirname = COLORBOX_DOWNLOAD_PREFIX . basename($filepath, '.zip');
// Remove any existing Colorbox plugin directory
// Remove any existing Colorbox plugin directory.
if (is_dir($dirname) || is_dir('colorbox')) {
drush_delete_dir($dirname, TRUE);
drush_delete_dir('colorbox', TRUE);
drush_log(dt('A existing Colorbox plugin was deleted from @path', array('@path' => $path)), 'notice');
}
// Decompress the zip archive
// Decompress the zip archive.
drush_tarball_extract($filename);
// Change the directory name to "colorbox" if needed.
......
<?php
/**
* @file
* Drupal\colorbox\ActivationCheckInterface.
*/
namespace Drupal\colorbox;
/**
......
<?php
/**
* @file
* Contains Drupal\colorbox\PageAttachmentInterface.
*/
namespace Drupal\colorbox;
use Drupal\Core\Extension\ModuleHandlerInterface;
......@@ -102,7 +97,8 @@ class ColorboxAttachment implements ElementAttachmentInterface {
$style = $this->settings->get('custom.style');
// Give other modules the possibility to override Colorbox settings and style.
// Give other modules the possibility to override Colorbox
// settings and style.
$this->moduleHandler->alter('colorbox_settings', $js_settings, $style);
// Add colorbox js settings.
......
......@@ -23,15 +23,15 @@ class ColorboxSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormID() {
public function getFormId() {
return 'colorbox_admin_settings_form';
}
/**
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['colorbox.settings',];
return ['colorbox.settings'];
}
/**
......@@ -74,7 +74,11 @@ class ColorboxSettingsForm extends ConfigFormBase {
$form['colorbox_custom_settings']['colorbox_transition_type'] = array(
'#type' => 'radios',
'#title' => $this->t('Transition type'),
'#options' => array('elastic' => $this->t('Elastic'), 'fade' => $this->t('Fade'), 'none' => $this->t('None')),
'#options' => array(
'elastic' => $this->t('Elastic'),
'fade' => $this->t('Fade'),
'none' => $this->t('None'),
),
'#default_value' => $config->get('custom.transition_type'),
'#description' => $this->t('The transition type.'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
......@@ -177,7 +181,7 @@ class ColorboxSettingsForm extends ConfigFormBase {
'#type' => 'checkbox',
'#title' => $this->t('Fixed'),
'#default_value' => $config->get('custom.fixed'),
'#description' => $this->t('If the Colorbox should be displayed in a fixed position within the visitor\'s viewport or relative to the document.'),
'#description' => $this->t("If the Colorbox should be displayed in a fixed position within the visitor's viewport or relative to the document."),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
);
$form['colorbox_custom_settings']['colorbox_scrolling'] = array(
......@@ -303,7 +307,7 @@ class ColorboxSettingsForm extends ConfigFormBase {
$config = $this->configFactory->getEditable('colorbox.settings');
$config
->set('custom.style', $form_state->getValue('colorbox_style'))
->set('custom.style', $form_state->getValue('colorbox_style'))
->set('custom.activate', $form_state->getValue('colorbox_custom_settings_activate'))
->set('custom.transition_type', $form_state->getValue('colorbox_transition_type'))
->set('custom.transition_speed', $form_state->getValue('colorbox_transition_speed'))
......@@ -363,7 +367,7 @@ class ColorboxSettingsForm extends ConfigFormBase {
],
static::STATE_SLIDESHOW_ENABLED => [
'visible' => [
':input[name="colorbox_slideshow"]' => ['value' => '1']
':input[name="colorbox_slideshow"]' => ['value' => '1'],
],
],
];
......@@ -373,11 +377,11 @@ class ColorboxSettingsForm extends ConfigFormBase {
/**
* Create a range for a series of options.
*
* @param number $start
* @param int $start
* The start of the range.
* @param number $end
* @param int $end
* The end of the range.
* @param number $step
* @param int $step
* The interval between elements.
*
* @return array
......
......@@ -125,7 +125,7 @@ class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPl
'#empty_option' => $this->t('None (original image)'),
'#options' => $image_styles_hide,
'#description' => $description_link->toRenderable() + [
'#access' => $this->currentUser->hasPermission('administer image styles')
'#access' => $this->currentUser->hasPermission('administer image styles'),
],
);
$element['colorbox_node_style_first'] = array(
......@@ -135,7 +135,7 @@ class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPl
'#empty_option' => $this->t('No special style.'),
'#options' => $image_styles,
'#description' => $description_link->toRenderable() + [
'#access' => $this->currentUser->hasPermission('administer image styles')
'#access' => $this->currentUser->hasPermission('administer image styles'),
],
);
$element['colorbox_image_style'] = array(
......@@ -145,7 +145,7 @@ class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPl
'#empty_option' => $this->t('None (original image)'),
'#options' => $image_styles,
'#description' => $description_link->toRenderable() + [
'#access' => $this->currentUser->hasPermission('administer image styles')
'#access' => $this->currentUser->hasPermission('administer image styles'),
],
);
......@@ -203,7 +203,7 @@ class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPl
}
$caption = array(
'auto' => $this->t('Automatic'),
'auto' => $this->t('Automatic'),
'title' => $this->t('Title text'),
'alt' => $this->t('Alt text'),
'entity_title' => $this->t('Content title'),
......@@ -301,7 +301,7 @@ class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPl
}
$caption = array(
'auto' => $this->t('Automatic'),
'auto' => $this->t('Automatic'),
'title' => $this->t('Title text'),
'alt' => $this->t('Alt text'),
'entity_title' => $this->t('Content title'),
......@@ -418,9 +418,10 @@ class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPl
if ($style_id && $style = ImageStyle::load($style_id)) {
if (!empty($dependencies[$style->getConfigDependencyKey()][$style->getConfigDependencyName()])) {
$replacement_id = $this->imageStyleStorage->getReplacementId($style_id);
// If a valid replacement has been provided in the storage, replace the
// image style with the replacement and signal that the formatter plugin
// settings were updated.
// If a valid replacement has been provided in the storage,
// replace the image style with the replacement and signal
// that the formatter plugin.
// Settings were updated.
if ($replacement_id && ImageStyle::load($replacement_id)) {
$this->setSetting($name, $replacement_id);
$changed = TRUE;
......
......@@ -34,6 +34,8 @@ class ColorboxJavascriptTest extends JavascriptTestBase {
const COLORBOX_WAIT_TIMEOUT = 500;
/**
* Node var.
*
* @var \Drupal\node\NodeInterface
*/
protected $node;
......@@ -84,7 +86,7 @@ class ColorboxJavascriptTest extends JavascriptTestBase {
}
/**
* Test the mobile detection
* Test the mobile detection.
*/
public function testMobileDetection() {
$this->changeSetting('advanced.mobile_detect', TRUE);
......@@ -177,7 +179,7 @@ class ColorboxJavascriptTest extends JavascriptTestBase {
'target_id' => $file_b->id(),
'alt' => 'Image alt 2',
'title' => 'Image title 2',
]
],
],
]);
}
......
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