You are here

function magnific_popup_field_formatter_settings_form in Magnific Popup 7

Implements hook_field_formatter_settings_form().

File

includes/magnific_popup.formatters.inc, line 30
Formatters for Magnific Popup.

Code

function magnific_popup_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];

  // Get all possible thumbnail fields.
  $all_fields = !empty($form['#fields']) ? $form['#fields'] : array();
  $field_bundle = !empty($form['#bundle']) ? $form['#bundle'] : '';
  $thumbnail_field_options = _magnific_popup_thumbnail_field_options($all_fields, $field_bundle);

  // Get all possible image styles.
  $image_style_options = _magnific_popup_image_style_options();

  // Gallery Mode is TRUE when this field supports multiple items.
  $gallery_available = $field['cardinality'] !== 1;
  $gallery_options = _magnific_popup_gallery_options();
  $element = array();
  $element['gallery_available'] = array(
    '#type' => 'markup',
    '#prefix' => '<p>',
    '#suffix' => '</p>',
  );
  $element['gallery_available']['#markup'] = $gallery_available ? t('This field configuration <strong>supports multiple items</strong> and can display itself as a gallery of items!') : t('This field configuration <strong>does not support multiple items</strong> and cannot display itself as a gallery of items.');
  $element['gallery_style'] = array(
    '#type' => 'select',
    '#title' => t('Gallery Type'),
    '#options' => $gallery_options,
    '#disabled' => !$gallery_available,
    '#default_value' => $settings['gallery_style'],
    '#description' => t('Choose how this gallery displays its triggering element(s).'),
  );
  $thumbnail_field = empty($settings['thumbnail_field']) ? $field['field_name'] : $settings['thumbnail_field'];
  $element['thumbnail_field'] = array(
    '#type' => 'select',
    '#title' => t('Image Thumbnail Field'),
    '#options' => $thumbnail_field_options,
    '#disabled' => empty($thumbnail_field_options),
    '#default_value' => $thumbnail_field,
    '#description' => t('Select field to be used as thumbnail (by default use the same field for popup as for thumbnail).'),
  );
  $thumbnail_style = empty($settings['thumbnail_style']) ? 'magnific_popup_thumbnail' : $settings['thumbnail_style'];
  $element['thumbnail_style'] = array(
    '#type' => 'select',
    '#title' => t('Thumbnail Style'),
    '#options' => $image_style_options,
    '#disabled' => empty($image_style_options),
    '#default_value' => $thumbnail_style,
    '#description' => t('Select the image style used to display the thumbnail.'),
  );
  return $element;
}