Commit c0635e14 authored by grisendo's avatar grisendo
Browse files

Visibility pages setting converted to array of strings

parent 8f3326e2
......@@ -157,11 +157,20 @@ function colorbox_update_8000() {
'colorbox_caption_trim' => 'advanced.caption_trim',
'colorbox_caption_trim_length' => 'advanced.caption_trim_length',
'colorbox_visibility' => 'advanced.visibility',
'colorbox_pages' => 'advanced.pages',
'colorbox_compression_type' => 'advanced.compression_type',
'colorbox_image_style' => 'insert.image_style',
'colorbox_insert_gallery' => 'insert.insert_gallery',
)
);
$sql = db_select('variable', 'v')
->fields('v', array('value'))
->condition('name', 'colorbox_pages')
->execute();
if ($row = $sql->fetchAssoc()) {
$val = unserialize($row['value']);
$pages = _colorbox_string_textarea_to_array($val);
$conf = config('colorbox.settings');
$conf->set('advanced.pages', $pages);
}
}
......@@ -123,7 +123,7 @@ function _colorbox_active() {
// Code from the block_list funtion in block.module.
$path = Drupal::service('path.alias_manager.cached')->getPathAlias($current_path);
$colorbox_pages = $config->get('colorbox_pages');
$colorbox_pages = _colorbox_array_to_string_textarea($config->get('advanced.pages'));
// Compare with the internal and path alias (if any).
$page_match = drupal_match_path($path, $colorbox_pages);
if ($path != $current_path) {
......@@ -163,3 +163,24 @@ function colorbox_insert_content($item, $style, $widget) {
function colorbox_gallery_exists() {
return FALSE;
}
/**
* Converts a text with lines (\n) into an array of lines.
*
* @return
* Array with as many items as non-empty lines in the text
*/
function _colorbox_string_textarea_to_array($text) {
$text = str_replace("\r\n", "\n", $text);
return array_filter(explode("\n", $text), 'trim');
}
/**
* Converts an array of lines into an text with lines (\n).
*
* @return
* Text with lines
*/
function _colorbox_array_to_string_textarea($array) {
return implode("\r\n", $array);
}
......@@ -30,7 +30,17 @@ advanced:
caption_trim: '0'
caption_trim_length: '75'
visibility: '0'
pages: 'admin*\nimagebrowser*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit\nprint/*\nprintpdf/*\nsystem/ajax\nsystem/ajax/*'
pages:
- 'admin*'
- 'imagebrowser*'
- 'img_assist*'
- 'imce*'
- 'node/add/*'
- 'node/*/edit'
- 'print/*'
- 'printpdf/*'
- 'system/ajax'
- 'system/ajax/*'
compression_type: 'minified'
insert:
image_style: ''
......
......@@ -100,8 +100,11 @@ colorbox.settings:
type: integer
label: 'Show Colorbox on specific pages'
pages:
type: string
type: sequence
label: 'Pages'
sequence:
- type: string
label: 'Page'
compression_type:
type: string
label: 'Colorbox compression level'
......
......@@ -318,7 +318,7 @@ class ColorboxSettingsForm extends SystemConfigFormBase {
$form['colorbox_advanced_settings']['colorbox_pages'] = array(
'#type' => 'textarea',
'#title' => '<span class="element-invisible">' . t('Pages') . '</span>',
'#default_value' => $config->get('advanced.pages'),
'#default_value' => _colorbox_array_to_string_textarea($config->get('advanced.pages')),
'#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(
......@@ -373,7 +373,7 @@ class ColorboxSettingsForm extends SystemConfigFormBase {
->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', $form_values['colorbox_pages'])
->set('advanced.pages', _colorbox_string_textarea_to_array($form_values['colorbox_pages']))
->set('advanced.compression_type', $form_values['colorbox_compression_type']);
if (isset($form_values['colorbox_image_style'])) {
......
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