Commit aa5ddcc2 authored by Karsa's avatar Karsa Committed by yukare

Fix for issue #1751666 by Karsa: Decrease the number of field formatters

parent 14275a5e
......@@ -27,6 +27,7 @@ function theme_lightbox2_image($variables) {
$image_style = $variables['image_style'];
$node_id = $variables['node_id'];
$field_name = $variables['field_name'];
$caption = $variables['caption'];
if (!$variables["lightbox_style"]) {
$path['path'] = file_create_url($item['uri']);
......@@ -66,7 +67,26 @@ function theme_lightbox2_image($variables) {
$rel .= ']';
// Title Start
$rel .= '[' . $item['title'];
$rel .= '[';
switch($caption) {
case 'hidden':
break;
case 'filename':
$rel .= $item['filename'];
break;
case 'title':
$rel .= $item['title'];
break;
default:
$caption_display = array(
'label' => 'hidden',
);
$entity = entity_load('file', array($item['fid']));
$entity = $entity[$item['fid']];
$rel.=drupal_render(field_view_field('file', $entity, $caption, $caption_display));
break;
}
// Download Link
if (user_access('download original image')) {
......
......@@ -797,6 +797,112 @@ function lightbox2_add_files() {
}
}
/**
* Helper function for image styles.
*/
function lightbox2_image_styles() {
$image_styles=array('0'=>'original');
$tmp=image_styles();
foreach($tmp as $style) {
$image_styles[$style['name']] = $style['name'];
}
return $image_styles;
}
/**
* Helper function for possible fields to display as the caption.
*/
function lightbox2_image_fields() {
$fields = array(
'hidden' => t('Hidden'),
'title' => t('File title'),
'filename' => t('Filename'),
);
foreach(field_info_instances("file", "image") as $field) {
$fields[$field['field_name']] = $field['label'];
}
return $fields;
}
/**
* Helper function for possible lightbox styles.
*/
function lightbox2_lightbox_types() {
return array(
'lightbox' => t('Single lightbox'),
'lightshow' => t('Lightshow'),
);
}
/**
* Implements hook_field_formatter_settings_form().
*/
function lightbox2_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$form = array();
$form['type'] = array(
'#title' => t('Lightbox type'),
'#type' => 'select',
'#options' => lightbox2_lightbox_types(),
'#default_value' => $settings['type'],
);
$form['image_style'] = array(
'#title' => t('Image style'),
'#description' => t('The thumbnail to display as a link for the lightbox.'),
'#type' => 'select',
'#options' => lightbox2_image_styles(),
'#default_value' => $settings['image_style'],
);
$form['lightbox_style'] = array(
'#title' => t('Lightbox style'),
'#description' => t('The image style to show inside the lightbox.'),
'#type' => 'select',
'#options' => lightbox2_image_styles(),
'#default_value' => $settings['lightbox_style'],
);
$form['caption'] = array(
'#title' => t('Caption field'),
'#description' => t('The field to use as a caption.'),
'#type' => 'select',
'#options' => lightbox2_image_fields(),
'#default_value' => $settings['caption'],
);
return $form;
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function lightbox2_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$image_styles = lightbox2_image_styles();
$fields = lightbox2_image_fields();
$types = lightbox2_lightbox_types();
$summary = '';
if(isset($settings['caption']) && isset($settings['type']) && isset($settings['image_style']) && isset($settings['lightbox_style'])) {
$summary .= '<strong>'.t('Caption field') . '</strong>: ' . $fields[$settings['caption']] . '<br/>';
$summary .= '<strong>'.t('Display') . '</strong>: ' ;
$summary .= $types[$settings['type']];
$summary .= ': ';
$summary .= $image_styles[$settings['image_style']];
$summary .= ' => ';
$summary .= $image_styles[$settings['lightbox_style']];
} else {
$summary = 'Title - Lightbox: original => original';
}
return $summary;
}
/**
* Implementation of hook_field_formatter_info().
*
......@@ -807,22 +913,16 @@ function lightbox2_add_files() {
function lightbox2_field_formatter_info() {
$formatters = array();
if (module_exists('image')) {
$image = $lightbox = image_styles();
$types = array('lightbox', 'lightshow');
foreach ($types as $type) {
foreach ($image as $image_key => $image_value ) {
$formatters['lightbox2__' . $type . '__' . $image_key . '__original'] = array(
'label' => 'Lightbox2: ' . $type . ': ' . $image_key . '->original',
'field types' => array('image'),
);
foreach ($lightbox as $lightbox_key => $lightbox_value ) {
$formatters['lightbox2__' . $type . '__' . $image_key . "__" . $lightbox_key] = array(
'label' => 'Lightbox2: ' . $type . ': ' . $image_key . '->' . $lightbox_key,
'field types' => array('image'),
);
}
}
}
$formatters['lightbox2'] = array(
'label' => 'Lightbox2',
'field types' => array('image'),
'settings' => array(
'type' => 'lightbox',
'image_style' => 'original',
'lightbox_style' => 'original',
'caption' => 'hidden',
),
);
}
return $formatters;
/*
......@@ -946,10 +1046,10 @@ function lightbox2_field_formatter_info() {
*/
function lightbox2_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$pieces = explode('__', $display['type']);
$lightbox_type = $pieces[1];
$image_style = $pieces[2];
$lightbox_style = $pieces[3];
$settings = $display["settings"];
$lightbox_type = $settings['type'];
$image_style = $settings['image_style'];
$lightbox_style = $settings['lightbox_style'];
if ($image_style == 'original') {
$image_style = NULL;
......@@ -974,6 +1074,7 @@ function lightbox2_field_formatter_view($entity_type, $entity, $field, $instance
'#path' => $uri,
'#node_id' => $wrapper->getIdentifier(),
'#field_name' => $field['field_name'],
'#caption' => $settings['caption'],
);
}
return ($element);
......@@ -1024,6 +1125,7 @@ function lightbox2_theme($existing, $type, $theme, $path) {
'lightbox_style' => NULL,
'node_id' => NULL,
'field_name' => NULL,
'caption' => NULL,
),
//'variables' => array(),
);
......
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