Commit e670c9df authored by lakshminp's avatar lakshminp Committed by frjo

Issue #2399929 by lakshminp: API changes updates for Drupal 8 to avoid WSOD.

parent 8b77cfe4
......@@ -6,6 +6,7 @@
*/
use Drupal\Core\Url;
use Drupal\Component\Utility\Unicode;
/**
* Implements hook_requirements().
......@@ -15,7 +16,7 @@ function colorbox_requirements($phase) {
if ($phase == 'runtime') {
$library = libraries_detect('colorbox');
$error_type = isset($library['error']) ? drupal_ucfirst($library['error']) : '';
$error_type = isset($library['error']) ? Unicode::ucfirst($library['error']) : '';
$error_message = isset($library['error message']) ? $library['error message'] : '';
if (empty($library['installed'])) {
......
colorbox:
version: VERSION
js:
js/colorbox.js: {}
dependencies:
- core/jquery
- core/drupal
settings:
version: VERSION
js:
js/colorbox_admin_settings.js: { preprocess: false }
dependencies:
- core/jquery
- core/drupal
plain:
version: VERSION
js:
styles/plain/colorbox_style.js: {}
css:
theme:
styles/plain/colorbox_style.css: {}
dependencies:
- colorbox/colorbox
- core/jquery
- core/drupal
stockholmsyndrome:
version: VERSION
js:
styles/stockholmsyndrome/colorbox_style.js: {}
css:
theme:
styles/stockholmsyndrome/colorbox_style.css: {}
dependencies:
- colorbox/colorbox
- core/jquery
- core/drupal
default:
version: VERSION
js:
styles/default/colorbox_style.js: {}
css:
theme:
styles/default/colorbox_style.css: {}
dependencies:
- colorbox/colorbox
- core/jquery
- core/drupal
......@@ -7,6 +7,7 @@
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Path\PathMatcher;
use Drupal\Core\Url;
/**
* The default path to the Colorbox directory.
......@@ -91,25 +92,28 @@ function colorbox_page_attachments(&$page) {
// Give other modules the possibility to override Colorbox settings and style.
\Drupal::moduleHandler()->alter('colorbox_settings', $js_settings, $style);
$page['#attached']['js'][] = array('type' => 'setting', 'data' => array('colorbox' => $js_settings));
$page['#attached']['drupalSettings']['colorbox'] = $js_settings;
// Add and initialise the Colorbox plugin.
$variant = $config->get('advanced.compression_type');
libraries_load('colorbox', $variant);
$page['#attached']['js'][$path . '/js/colorbox.js'] = array();
$page['#attached']['library'][] = 'colorbox/colorbox';
// Add JS and CSS based on selected style.
switch ($style) {
case 'none':
break;
case 'default':
$page['#attached']['library'][] = 'colorbox/default';
break;
case 'plain':
$page['#attached']['library'][] = 'colorbox/plain';
break;
case 'stockholmsyndrome':
$page['#attached']['css'][$path . '/styles/' . $style . '/colorbox_style.css'] = array();
$page['#attached']['js'][$path . '/styles/' . $style . '/colorbox_style.js'] = array();
$page['#attached']['library'][] = 'colorbox/stockholmsyndrome';
break;
default:
$page['#attached']['css'][$path . '/styles/' . $style . '/colorbox.css'] = array();
$page['#attached']['library'][] = 'colorbox/default';
}
$already_added = TRUE;
......@@ -178,7 +182,7 @@ function _colorbox_active() {
$pages = Unicode::strtolower(_colorbox_array_to_string($config->get('advanced.pages')));
// Compare the lowercase path alias (if any) and internal path.
$path = current_path();
$path = Url::fromRoute('<current>')->toString();
$path_alias = Unicode::strtolower(\Drupal::service('path.alias_storage')->lookupPathAlias($path, 'en'));
$page_match = \Drupal::service('path.matcher')->matchPath($path_alias, $pages);
if ($path_alias != $path) {
......
......@@ -30,7 +30,7 @@ class ColorboxSettingsForm extends ConfigFormBase {
// Get all settings
$config = $this->config('colorbox.settings');
$form['#attached']['js'][] = array('data' => drupal_get_path('module', 'colorbox') . '/js/colorbox_admin_settings.js', 'preprocess' => FALSE);
$form['#attached']['library'][] = 'colorbox/settings';
$library = libraries_detect('colorbox');
......@@ -303,44 +303,43 @@ class ColorboxSettingsForm extends ConfigFormBase {
// Get config factory
$config = $this->configFactory->get('colorbox.settings');
$form_values = $form_state['values'];
$config
->set('custom.style', $form_values['colorbox_style'])
->set('custom.activate', $form_values['colorbox_custom_settings_activate'])
->set('custom.transition_type', $form_values['colorbox_transition_type'])
->set('custom.transition_speed', $form_values['colorbox_transition_speed'])
->set('custom.opacity', $form_values['colorbox_opacity'])
->set('custom.text_current', $form_values['colorbox_text_current'])
->set('custom.text_previous', $form_values['colorbox_text_previous'])
->set('custom.text_next', $form_values['colorbox_text_next'])
->set('custom.text_close', $form_values['colorbox_text_close'])
->set('custom.overlayclose', $form_values['colorbox_overlayclose'])
->set('custom.maxwidth', $form_values['colorbox_maxwidth'])
->set('custom.maxheight', $form_values['colorbox_maxheight'])
->set('custom.initialwidth', $form_values['colorbox_initialwidth'])
->set('custom.initialheight', $form_values['colorbox_initialheight'])
->set('custom.fixed', $form_values['colorbox_fixed'])
->set('custom.scrolling', $form_values['colorbox_scrolling'])
->set('custom.slideshow.slideshow', $form_values['colorbox_slideshow'])
->set('custom.slideshow.auto', $form_values['colorbox_slideshowauto'])
->set('custom.slideshow.speed', $form_values['colorbox_slideshowspeed'])
->set('custom.slideshow.text_start', $form_values['colorbox_text_start'])
->set('custom.slideshow.text_stop', $form_values['colorbox_text_stop'])
->set('advanced.mobile_detect', $form_values['colorbox_mobile_detect'])
->set('advanced.mobile_detect_width', $form_values['colorbox_mobile_device_width'])
->set('advanced.caption_trim', $form_values['colorbox_caption_trim'])
->set('advanced.caption_trim_length', $form_values['colorbox_caption_trim_length'])
->set('advanced.visibility', $form_values['colorbox_visibility'])
->set('advanced.pages', _colorbox_string_to_array($form_values['colorbox_pages']))
->set('advanced.compression_type', $form_values['colorbox_compression_type']);
->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'))
->set('custom.opacity', $form_state->getValue('colorbox_opacity'))
->set('custom.text_current', $form_state->getValue('colorbox_text_current'))
->set('custom.text_previous', $form_state->getValue('colorbox_text_previous'))
->set('custom.text_next', $form_state->getValue('colorbox_text_next'))
->set('custom.text_close', $form_state->getValue('colorbox_text_close'))
->set('custom.overlayclose', $form_state->getValue('colorbox_overlayclose'))
->set('custom.maxwidth', $form_state->getValue('colorbox_maxwidth'))
->set('custom.maxheight', $form_state->getValue('colorbox_maxheight'))
->set('custom.initialwidth', $form_state->getValue('colorbox_initialwidth'))
->set('custom.initialheight', $form_state->getValue('colorbox_initialheight'))
->set('custom.fixed', $form_state->getValue('colorbox_fixed'))
->set('custom.scrolling', $form_state->getValue('colorbox_scrolling'))
->set('custom.slideshow.slideshow', $form_state->getValue('colorbox_slideshow'))
->set('custom.slideshow.auto', $form_state->getValue('colorbox_slideshowauto'))
->set('custom.slideshow.speed', $form_state->getValue('colorbox_slideshowspeed'))
->set('custom.slideshow.text_start', $form_state->getValue('colorbox_text_start'))
->set('custom.slideshow.text_stop', $form_state->getValue('colorbox_text_stop'))
->set('advanced.mobile_detect', $form_state->getValue('colorbox_mobile_detect'))
->set('advanced.mobile_detect_width', $form_state->getValue('colorbox_mobile_device_width'))
->set('advanced.caption_trim', $form_state->getValue('colorbox_caption_trim'))
->set('advanced.caption_trim_length', $form_state->getValue('colorbox_caption_trim_length'))
->set('advanced.visibility', $form_state->getValue('colorbox_visibility'))
->set('advanced.pages', _colorbox_string_to_array($form_state->getValue('colorbox_pages')))
->set('advanced.compression_type', $form_state->getValue('colorbox_compression_type'));
if (isset($form_values['colorbox_image_style'])) {
$config->set('insert.image_style', $form_values['colorbox_image_style']);
if ($form_state->getValue('colorbox_image_style')) {
$config->set('insert.image_style', $form_state->getValue('colorbox_image_style'));
}
if (isset($form_values['colorbox_insert_gallery'])) {
$config->set('insert.insert_gallery', $form_values['colorbox_insert_gallery']);
if ($form_state->getValue('colorbox_insert_gallery')) {
$config->set('insert.insert_gallery', $form_state->getValue('colorbox_insert_gallery'));
}
$config->save();
......
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