Commit 3b7ddca3 authored by frjo's avatar frjo
Browse files

Issue #1290208: Patch by frjo to add token support to captions.

parent 0ed469b8
......@@ -423,6 +423,7 @@ function colorbox_field_formatter_info() {
'colorbox_gallery' => 'post',
'colorbox_gallery_custom' => '',
'colorbox_caption' => 'auto',
'colorbox_caption_custom' => '',
),
),
);
......@@ -493,6 +494,7 @@ function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $
'title' => t('Title text'),
'alt' => t('Alt text'),
'node_title' => t('Node title'),
'custom' => t('Custom (with tokens)'),
'none' => t('None'),
);
$element['colorbox_caption'] = array(
......@@ -502,6 +504,41 @@ function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $
'#options' => $caption,
'#description' => t('Automatic will use the first none empty value of the title, the alt text and the node 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'),
),
),
);
if (module_exists('token')) {
$element['colorbox_token'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#theme' => 'token_tree',
'#token_types' => array('node'),
'#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;
}
......@@ -554,6 +591,7 @@ function colorbox_field_formatter_settings_summary($field, $instance, $view_mode
'title' => t('Title text'),
'alt' => t('Alt text'),
'node_title' => t('Node title'),
'custom' => t('Custom (with tokens)'),
'none' => t('None'),
);
if (isset($settings['colorbox_caption'])) {
......
......@@ -60,6 +60,14 @@ function theme_colorbox_image_formatter($variables) {
case 'node_title':
$caption = $node->title;
break;
case 'custom':
if (module_exists('token')) {
$caption = token_replace($settings['colorbox_caption_custom'], array('node' => $node));
}
else {
$caption = $settings['colorbox_caption_custom'];
}
break;
default:
$caption = '';
}
......
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