You are here

function field_slideshow_field_formatter_settings_form in Field Slideshow 7.2

Same name and namespace in other branches
  1. 7 field_slideshow.module \field_slideshow_field_formatter_settings_form()

Implements hook_field_formatter_settings_form().

File

./field_slideshow.module, line 59
Implement a slideshow formatter for fields.

Code

function field_slideshow_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $states = array();
  if ($field['type'] == 'field_collection') {
    $name_prefix = 'fields[' . $field['field_name'] . '][settings_edit_form][settings]';
    $states = array(
      'required' => array(
        ':input[name="' . $name_prefix . '[slideshow_content_type]"]' => array(
          'value' => 'image',
        ),
      ),
      'visible' => array(
        ':input[name="' . $name_prefix . '[slideshow_content_type]"]' => array(
          'value' => 'image',
        ),
      ),
    );
    $element['slideshow_content_type'] = array(
      '#title' => t('Type of content'),
      '#type' => 'select',
      '#default_value' => $settings['slideshow_content_type'],
      '#options' => array(
        'image' => t('Image'),
        'rendered_entity' => t('Rendered entity'),
      ),
      '#required' => TRUE,
    );
    $entity_info = entity_get_info('field_collection_item');
    $options = array();
    foreach ($entity_info['view modes'] as $key => $value) {
      $options[$key] = $value['label'];
    }
    $element['slideshow_view_mode'] = array(
      '#title' => t('View mode'),
      '#type' => 'select',
      '#default_value' => $settings['slideshow_view_mode'],
      '#options' => $options,
      '#states' => array(
        'required' => array(
          ':input[name="' . $name_prefix . '[slideshow_content_type]"]' => array(
            'value' => 'rendered_entity',
          ),
        ),
        'visible' => array(
          ':input[name="' . $name_prefix . '[slideshow_content_type]"]' => array(
            'value' => 'rendered_entity',
          ),
        ),
      ),
    );
    $element['slideshow_field_collection_image'] = array(
      '#title' => t('Image field'),
      '#type' => 'select',
      '#default_value' => $settings['slideshow_field_collection_image'],
      '#empty_option' => t('None'),
      '#options' => _field_slideshow_get_fields(array(
        'image',
        'imagefield_crop',
      ), $field['type'], $field['field_name']),
      '#states' => $states,
    );
  }
  if ($field['type'] != 'file') {
    $element['slideshow_image_style'] = array(
      '#title' => t('Image style'),
      '#type' => 'select',
      '#default_value' => $settings['slideshow_image_style'],
      '#empty_option' => t('None (original image)'),
      '#options' => image_style_options(FALSE),
      '#states' => $states,
    );
  }
  else {
    $element['slideshow_file_style'] = array(
      '#title' => t('File style'),
      '#type' => 'select',
      '#default_value' => $settings['slideshow_file_style'],
      '#empty_option' => t('small'),
      '#options' => _file_style_options(FALSE),
      '#states' => $states,
    );
  }
  $links = array(
    'content' => t('Content'),
    'file' => t('File'),
  );
  if ($field['type'] == 'media' || $field['type'] == 'field_collection') {
    $links += _field_slideshow_get_fields(array(
      'link_field',
      'node_reference',
      'entityreference',
    ), $field['type'], $field['field_name']);
  }
  $element['slideshow_link'] = array(
    '#title' => t('Link image to'),
    '#type' => 'select',
    '#default_value' => $settings['slideshow_link'],
    '#empty_option' => t('Nothing'),
    '#options' => $links,
  );
  if (module_exists('colorbox')) {
    $element['slideshow_link']['#options']['colorbox'] = 'Colorbox';
    $element['slideshow_colorbox_image_style'] = array(
      '#title' => t('Colorbox image style'),
      '#type' => 'select',
      '#default_value' => $settings['slideshow_colorbox_image_style'],
      '#empty_option' => t('None (original image)'),
      '#options' => image_style_options(FALSE),
      '#states' => array(
        'visible' => array(
          ':input[name$="[settings_edit_form][settings][slideshow_link]"]' => array(
            'value' => 'colorbox',
          ),
        ),
      ),
    );
    $colorbox_slideshow = array(
      'automatic' => t('Automatic'),
      'manual' => t('Manual'),
    );
    $element['slideshow_colorbox_slideshow'] = array(
      '#title' => t('Colorbox slideshow'),
      '#type' => 'select',
      '#default_value' => $settings['slideshow_colorbox_slideshow'],
      '#empty_option' => t('No slideshow'),
      '#options' => $colorbox_slideshow,
      '#states' => array(
        'visible' => array(
          ':input[name$="[settings_edit_form][settings][slideshow_link]"]' => array(
            'value' => 'colorbox',
          ),
        ),
      ),
    );
    $element['slideshow_colorbox_slideshow_speed'] = array(
      '#title' => t('Colorbox slideshow speed'),
      '#type' => 'textfield',
      '#size' => 5,
      '#default_value' => $settings['slideshow_colorbox_slideshow_speed'],
      '#description' => t('Time between transitions (ms).'),
      '#states' => array(
        'invisible' => array(
          ':input[name$="[settings_edit_form][settings][slideshow_colorbox_slideshow]"]' => array(
            'value' => '',
          ),
        ),
      ),
    );
    $colorbox_transitions = array(
      'none' => t('None'),
      'elastic' => t('Elastic'),
      'fade' => t('Fade'),
    );
    $element['slideshow_colorbox_transition'] = array(
      '#title' => t('Colorbox transition'),
      '#type' => 'select',
      '#default_value' => $settings['slideshow_colorbox_transition'],
      '#options' => $colorbox_transitions,
      '#states' => array(
        'visible' => array(
          ':input[name$="[settings_edit_form][settings][slideshow_link]"]' => array(
            'value' => 'colorbox',
          ),
        ),
      ),
    );
    $element['slideshow_colorbox_speed'] = array(
      '#title' => t('Colorbox transition speed'),
      '#type' => 'textfield',
      '#size' => 5,
      '#default_value' => $settings['slideshow_colorbox_speed'],
      '#description' => t('Duration of transition (ms).'),
      '#states' => array(
        'visible' => array(
          ':input[name$="[settings_edit_form][settings][slideshow_link]"]' => array(
            'value' => 'colorbox',
          ),
        ),
      ),
    );
  }
  if ($field['type'] == 'media' || $field['type'] == 'file' || $field['type'] == 'field_collection') {
    $captions = _field_slideshow_get_fields(array(
      'text',
    ), $field['type'], $field['field_name']);
  }
  else {
    $captions = array(
      'title' => t('Title text'),
      'alt' => t('Alt text'),
    );
  }
  $element['slideshow_caption'] = array(
    '#title' => t('Caption'),
    '#type' => 'select',
    '#default_value' => $settings['slideshow_caption'],
    '#empty_option' => t('Nothing'),
    '#options' => $captions,
  );
  $element['slideshow_caption_link'] = array(
    '#title' => t('Caption link'),
    '#type' => 'select',
    '#default_value' => $settings['slideshow_caption_link'],
    '#empty_option' => t('Nothing'),
    '#options' => $links,
    '#states' => array(
      'invisible' => array(
        ':input[name$="[settings_edit_form][settings][slideshow_caption]"]' => array(
          'value' => '',
        ),
      ),
    ),
  );
  if (module_exists('colorbox')) {
    $element['slideshow_caption_link']['#options']['colorbox'] = 'Colorbox';
  }
  $element['slideshow_fx'] = array(
    '#title' => t('Transition effect'),
    '#type' => 'select',
    '#default_value' => $settings['slideshow_fx'],
    '#options' => array(
      'blindX' => t('blindX'),
      'blindY' => t('blindY'),
      'blindZ' => t('blindZ'),
      'cover' => t('cover'),
      'curtainX' => t('curtainX'),
      'curtainY' => t('curtainY'),
      'fade' => t('fade'),
      'fadeZoom' => t('fadeZoom'),
      'growX' => t('growX'),
      'growY' => t('growY'),
      'scrollUp' => t('scrollUp'),
      'scrollDown' => t('scrollDown'),
      'scrollLeft' => t('scrollLeft'),
      'scrollRight' => t('scrollRight'),
      'scrollHorz' => t('scrollHorz'),
      'scrollVert' => t('scrollVert'),
      'shuffle' => t('shuffle'),
      'slideX' => t('slideX'),
      'slideY' => t('slideY'),
      'toss' => t('toss'),
      'turnUp' => t('turnUp'),
      'turnDown' => t('turnDown'),
      'turnLeft' => t('turnLeft'),
      'turnRight' => t('turnRight'),
      'uncover' => t('uncover'),
      'wipe' => t('wipe'),
      'zoom' => t('zoom'),
    ),
  );
  $element['slideshow_speed'] = array(
    '#title' => t('Transition speed'),
    '#type' => 'textfield',
    '#size' => 5,
    '#default_value' => $settings['slideshow_speed'],
    '#description' => t('Duration of transition (ms).'),
    '#required' => TRUE,
  );
  $element['slideshow_timeout'] = array(
    '#title' => t('Timeout'),
    '#type' => 'textfield',
    '#size' => 5,
    '#default_value' => $settings['slideshow_timeout'],
    '#description' => t('Time between transitions (ms). Enter 0 to disable automatic transitions (then, enable pager and/or controls).'),
    '#required' => TRUE,
  );
  $element['slideshow_order'] = array(
    '#title' => t('Order'),
    '#type' => 'select',
    '#default_value' => $settings['slideshow_order'],
    '#empty_option' => t('Normal'),
    '#options' => array(
      'reverse' => t('Reverse'),
      'random' => t('Random'),
    ),
  );
  $element['slideshow_controls'] = array(
    '#title' => t('Create prev/next controls'),
    '#type' => 'checkbox',
    '#default_value' => $settings['slideshow_controls'],
  );
  $element['slideshow_controls_pause'] = array(
    '#title' => t('Create play/pause button'),
    '#type' => 'checkbox',
    '#default_value' => $settings['slideshow_controls_pause'],
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][slideshow_controls]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $element['slideshow_controls_position'] = array(
    '#title' => t('Prev/next controls position'),
    '#type' => 'select',
    '#options' => array(
      'before' => 'Before',
      'after' => 'After',
    ),
    '#default_value' => $settings['slideshow_controls_position'],
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][slideshow_controls]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $element['slideshow_pause'] = array(
    '#title' => t('Pause on hover'),
    '#type' => 'checkbox',
    '#default_value' => $settings['slideshow_pause'],
  );
  $element['slideshow_start_on_hover'] = array(
    '#title' => t('Activate on hover'),
    '#type' => 'checkbox',
    '#default_value' => $settings['slideshow_start_on_hover'],
  );
  $element['slideshow_pager'] = array(
    '#title' => t('Pager'),
    '#type' => 'select',
    '#options' => array(
      'number' => 'Slide number',
      'image' => 'Image',
      'carousel' => 'Carousel',
    ),
    '#empty_option' => t('None'),
    '#default_value' => $settings['slideshow_pager'],
  );
  $element['slideshow_pager_position'] = array(
    '#title' => t('Pager position'),
    '#type' => 'select',
    '#options' => array(
      'before' => 'Before',
      'after' => 'After',
    ),
    '#default_value' => $settings['slideshow_pager_position'],
    '#states' => array(
      'invisible' => array(
        ':input[name$="[settings_edit_form][settings][slideshow_pager]"]' => array(
          'value' => '',
        ),
      ),
    ),
  );
  $element['slideshow_pager_image_style'] = array(
    '#title' => t('Pager image style'),
    '#type' => 'select',
    '#default_value' => $settings['slideshow_pager_image_style'],
    '#empty_option' => t('None (original image)'),
    '#options' => image_style_options(FALSE),
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][slideshow_pager]"]' => array(
          'value' => 'image',
        ),
      ),
    ),
  );
  $element['slideshow_carousel_image_style'] = array(
    '#title' => t('Carousel: Image style'),
    '#type' => 'select',
    '#default_value' => $settings['slideshow_carousel_image_style'],
    '#empty_option' => t('None (original image)'),
    '#options' => image_style_options(FALSE),
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][slideshow_pager]"]' => array(
          'value' => 'carousel',
        ),
      ),
    ),
  );
  $element['slideshow_carousel_visible'] = array(
    '#title' => t('Carousel: Number of visible images'),
    '#type' => 'textfield',
    '#size' => 2,
    '#default_value' => $settings['slideshow_carousel_visible'],
    '#description' => t('The number of images that are visible in the pager. Defaults to 3.'),
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][slideshow_pager]"]' => array(
          'value' => 'carousel',
        ),
      ),
    ),
  );
  $element['slideshow_carousel_scroll'] = array(
    '#title' => t('Carousel: Number of images to scroll by'),
    '#type' => 'textfield',
    '#size' => 2,
    '#default_value' => $settings['slideshow_carousel_scroll'],
    '#description' => t('The number of images scrolled with each click. Defaults to 1.'),
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][slideshow_pager]"]' => array(
          'value' => 'carousel',
        ),
      ),
    ),
  );
  $element['slideshow_carousel_speed'] = array(
    '#title' => t('Carousel: Transition speed'),
    '#type' => 'textfield',
    '#size' => 5,
    '#default_value' => $settings['slideshow_carousel_speed'],
    '#description' => t('Speed of the Carousel scroll. Defaults to 500.'),
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][slideshow_pager]"]' => array(
          'value' => 'carousel',
        ),
      ),
    ),
  );
  $skin_options = array();
  if (($library = libraries_load('jquery.carousel')) && !empty($library['loaded'])) {
    $path = libraries_get_path('jquery.jcarousel') . '/skins';
    if (is_dir($path)) {
      $dirnames = scandir($path);
      foreach ($dirnames as $dirname) {
        $dirname = check_plain($dirname);
        if (is_dir($path . '/' . $dirname) && file_exists($path . '/' . $dirname . '/skin.css')) {
          $skin_options[$dirname] = $dirname;
        }
      }
    }
  }
  $element['slideshow_carousel_skin'] = array(
    '#title' => t('Carousel Skin'),
    '#type' => 'select',
    '#default_value' => $settings['slideshow_carousel_skin'],
    '#options' => $skin_options,
    '#empty_option' => t('None'),
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][slideshow_pager]"]' => array(
          'value' => 'carousel',
        ),
      ),
    ),
  );
  $element['slideshow_carousel_follow'] = array(
    '#title' => t('Follow active slide'),
    '#type' => 'checkbox',
    '#default_value' => $settings['slideshow_carousel_follow'],
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][slideshow_pager]"]' => array(
          'value' => 'carousel',
        ),
      ),
    ),
  );
  $element['slideshow_carousel_vertical'] = array(
    '#title' => t('Vertical Carousel'),
    '#type' => 'checkbox',
    '#default_value' => $settings['slideshow_carousel_vertical'],
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][slideshow_pager]"]' => array(
          'value' => 'carousel',
        ),
      ),
    ),
  );
  $element['slideshow_carousel_circular'] = array(
    '#title' => t('Circular Carousel'),
    '#type' => 'checkbox',
    '#default_value' => $settings['slideshow_carousel_circular'],
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][slideshow_pager]"]' => array(
          'value' => 'carousel',
        ),
      ),
    ),
  );
  return $element;
}