juicebox = juicebox();
}
/**
* Define default plugin options.
*/
function option_definition() {
$options = parent::option_definition();
// Get the base settings.
$base_settings = $this->juicebox->confBaseOptions();
$library = $this->juicebox->library;
// Structure the base settings in the "default" format that views wants.
foreach ($base_settings as $setting => $value) {
$base_settings_default[$setting] = array('default' => $value);
}
$options = array_merge($base_settings_default, array(
'image_field' => array('default' => ''),
// If the library supports multi-size we can default to that for the main
// image, otherwise use the "medium" style.
'image_field_style' => array('default' => (!empty($library['version']) && !in_array('juicebox_multisize_image_style', $library['disallowed_conf'])) ? 'juicebox_multisize' : 'juicebox_medium'),
'thumb_field' => array('default' => ''),
'thumb_field_style' => array('default' => 'juicebox_square_thumbnail'),
'title_field' => array('default' => ''),
'caption_field' => array('default' => ''),
'show_title' => array('default' => 0),
));
return $options;
}
/**
* Define plugin options form.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$settings = $this->options;
// Get the active field options.
$options = $this->confGetFieldSources();
$missing_field_warning = '';
if (empty($options['field_options_images'])) {
$missing_field_warning = t('You must add a field of type image, file or file ID to your view display before this value can be set.
');
}
// Add the view-specific elements.
$form['image_field'] = array(
'#type' => 'select',
'#title' => t('Image Source'),
'#default_value' => $settings['image_field'],
'#description' => t('The field source to use for each image in the gallery. Must be an image field, file field or a file ID.'),
'#suffix' => $missing_field_warning,
'#options' => $options['field_options_images'],
'#empty_option' => t('- Select -'),
);
$form['thumb_field'] = array(
'#type' => 'select',
'#title' => t('Thumbnail Source'),
'#default_value' => $settings['thumb_field'],
'#description' => t('The field source to use for each thumbnail in the gallery. Must be an image field, file field or a file ID. Typically you will choose the same value that was set in the "Image Source" option above.'),
'#suffix' => $missing_field_warning,
'#options' => $options['field_options_images'],
'#empty_option' => t('- Select -'),
);
$form['image_field_style'] = array(
'#type' => 'select',
'#title' => t('Image Field Style'),
'#default_value' => $settings['image_field_style'],
'#description' => t('The style formatter for the image. Any formatting settings configured on the field itself will be ignored and this style setting will always be used.'),
'#options' => $this->juicebox->confBaseStylePresets(),
'#empty_option' => t('None (original image)'),
);
$form['thumb_field_style'] = array(
'#type' => 'select',
'#title' => t('Thumbnail Field Style'),
'#default_value' => $settings['thumb_field_style'],
'#description' => t('The style formatter for the thumbnail. Any formatting settings configured on the field itself will be ignored and this style setting will always be used.'),
'#options' => $this->juicebox->confBaseStylePresets(FALSE),
'#empty_option' => t('None (original image)'),
);
$form['title_field'] = array(
'#type' => 'select',
'#title' => t('Title Field'),
'#default_value' => $settings['title_field'],
'#description' => t('The view\'s field that should be used for the title of each image in the gallery. Any formatting settings configured on the field itself will be respected.'),
'#options' => $options['field_options'],
'#empty_option' => t('None'),
);
$form['caption_field'] = array(
'#type' => 'select',
'#title' => t('Caption Field'),
'#default_value' => $settings['caption_field'],
'#description' => t('The view\'s field that should be used for the caption of each image in the gallery. Any formatting settings configured on the field itself will be respected.'),
'#options' => $options['field_options'],
'#empty_option' => t('None'),
);
$form['show_title'] = array(
'#type' => 'checkbox',
'#title' => t('Show Gallery Title'),
'#default_value' => $settings['show_title'],
'#description' => t('Show the view display title as the gallery title.'),
);
// Add the common form elements.
$form = $this->juicebox->confBaseForm($form, $settings);
// Add view-sepcific field options for the linkURL setting.
$linkurl_field_options = array();
foreach ($options['field_options'] as $field_key => $field_name) {
$linkurl_field_options[$field_key] = t('Field') . ' - ' . $field_name;
}
$form['linkurl_source']['#description'] = $form['linkurl_source']['#description'] . '' . t('If using a field source it must render a properly formatted URL and nothing else.') . '';
$form['linkurl_source']['#options'] = array_merge($form['linkurl_source']['#options'], $linkurl_field_options);
}
/**
* Define validation rules for the plugin display.
*/
function validate() {
$errors = parent::validate();
// Make sure block caching is not enabled. With block caching enabled the
// Juicebox javascript library may not get included.
if (isset($this->display->handler->options['block_caching']) && $this->display->handler->options['block_caching'] != DRUPAL_NO_CACHE) {
$errors[] = t('The Juicebox style cannot be used with block caching. Please disable the "Block caching" option for this display.');
}
// Make sure the pager is not enabled.
if ($this->display->handler->use_pager()) {
$errors[] = t('The Juicebox style cannot be used with a pager. Please disable the "Use pager" option for this display.');
}
// We want to somewhat "nag" the user if they have not yet configured the
// Juicebox-specific plugin settings (because things won't work until they
// do). However, we do NOT want to formally set an error. This is because
// this validate method can run on pages where the user can't actaully touch
// the Juicebox-specific plugin settings (such as
// admin/structure/views/add).
if (empty($this->options['image_field']) || empty($this->options['thumb_field'])) {
drupal_set_message(t("To ensure a fully functional Juicebox gallery please remember to add at least one field of type Image, File or File ID to your Juicebox view display, and to configure all Juicebox Gallery format settings. Once you have completed these steps, re-save your view to remove this warning."), 'warning', FALSE);
}
// Set warning about depreciated "Base file ID" source option if it's used.
if ($this->options['image_field'] == 'file_base' || $this->options['thumb_field'] == 'file_base') {
drupal_set_message(t('A Juicebox gallery used in your view is configured with an obsolete source setting of "Base file ID". Please add a File ID field to the related display and choose that instead for your image or thumb source within the Juicebox Gallery format settings. Once you have completed these steps, re-save your view to remove this warning.'), 'warning', FALSE);
}
return $errors;
}
/**
* Render the view page display.
*
* This is where the Juicebox embed code is built for the view.
*/
function render() {
$element = array();
$view = $this->view;
// If we are previewing the view in the admin interface all the necessary
//