You are here

function juicebox_style_plugin::options_form in Juicebox HTML5 Responsive Image Galleries 7

Define plugin options form.

Overrides views_plugin_style::options_form

File

plugins/juicebox_style_plugin.inc, line 52
Contains the Juicebox views style plugin.

Class

juicebox_style_plugin
Style plugin to render each item in a views list.

Code

function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);

  // Get the active field options
  $field_options = array();
  $field_options_images = array();
  $field_handlers = $this->display->handler
    ->get_handlers('field');
  foreach ($field_handlers as $field => $handler) {
    if ($label = $handler
      ->label()) {
      $name = $label;
    }
    else {
      $name = $handler
        ->ui_name();
    }

    // Separate image fields from non-image fields
    if (isset($handler->field_info['type'])) {
      if ($handler->field_info['type'] == 'image') {
        $field_options_images[$field] = $name;
      }
      else {
        $field_options[$field] = $name;
      }
    }
    else {
      $field_options[$field] = $name;
    }
  }

  // Get available image style presets
  $presets = image_style_options(FALSE);

  // Initialize the "settings" values before working with them. This is
  // required for legacy support.
  $settings = _juicebox_init_display_settings($this->options);

  // Start with the "common" form elements.
  $form = _juicebox_common_form_elements($form, $settings);

  // Add the view-specific elements.
  $form['image_field'] = array(
    '#type' => 'select',
    '#title' => t('Main Image Field'),
    '#default_value' => $settings['image_field'],
    '#description' => t('The view\'s image field that should be used for each image in the gallery.'),
    '#options' => $field_options_images,
  );
  $form['image_field_style'] = array(
    '#type' => 'select',
    '#title' => t('Main 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' => $presets,
    '#empty_option' => t('None (original image)'),
  );
  $form['thumb_field'] = array(
    '#type' => 'select',
    '#title' => t('Thumbnail Field'),
    '#default_value' => $settings['thumb_field'],
    '#description' => t('The view\'s image field that should be used for each thumbnail in the gallery. Typically you will choose the same value that was set in the "Main Image Field" option above.'),
    '#options' => $field_options_images,
  );
  $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' => $presets,
    '#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' => $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' => $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 view-sepcific field options for the linkURL setting.
  $linkurl_field_options = array();
  foreach ($field_options as $field_key => $field_name) {
    $linkurl_field_options[$field_key] = t('Field') . ' - ' . $field_name;
  }

  // Adjust some advanced settings that are specific to views.
  $form['linkurl_source']['#description'] = $form['linkurl_source']['#description'] . '</br><strong>' . t('If using a field for this source the field must render a properly formatted URL and nothing else.') . '</strong>';
  $form['linkurl_source']['#options'] = array_merge($form['linkurl_source']['#options'], $linkurl_field_options);
}