You are here

function colorbox_field_formatter_settings_form in Colorbox 7

Same name and namespace in other branches
  1. 7.2 colorbox.module \colorbox_field_formatter_settings_form()

Implements hook_field_formatter_settings_form().

File

./colorbox.module, line 420
A light-weight, customizable lightbox plugin for jQuery 1.3

Code

function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $image_styles = image_style_options(FALSE);
  $image_styles_hide = $image_styles;
  $image_styles_hide['hide'] = t('Hide (do not display image)');
  $element['colorbox_node_style'] = array(
    '#title' => t('Content image style'),
    '#type' => 'select',
    '#default_value' => $settings['colorbox_node_style'],
    '#empty_option' => t('None (original image)'),
    '#options' => $image_styles_hide,
    '#description' => t('Image style to use in the content.'),
  );
  $element['colorbox_image_style'] = array(
    '#title' => t('Colorbox image style'),
    '#type' => 'select',
    '#default_value' => $settings['colorbox_image_style'],
    '#empty_option' => t('None (original image)'),
    '#options' => $image_styles,
    '#description' => t('Image style to use in the Colorbox.'),
  );
  $gallery = array(
    'post' => t('Per post gallery'),
    'page' => t('Per page gallery'),
    'field_post' => t('Per field in post gallery'),
    'field_page' => t('Per field in page gallery'),
    'custom' => t('Custom'),
    'none' => t('No gallery'),
  );
  $element['colorbox_gallery'] = array(
    '#title' => t('Gallery (image grouping)'),
    '#type' => 'select',
    '#default_value' => $settings['colorbox_gallery'],
    '#options' => $gallery,
    '#description' => t('How Colorbox should group the image galleries.'),
  );
  $element['colorbox_gallery_custom'] = array(
    '#title' => t('Custom gallery'),
    '#type' => 'machine_name',
    '#maxlength' => 32,
    '#default_value' => $settings['colorbox_gallery_custom'],
    '#description' => t('All images on a page with the same gallery value (rel attribute) will be grouped together. It must only contain lowercase letters, numbers, and underscores.'),
    '#required' => FALSE,
    '#machine_name' => array(
      'exists' => 'colorbox_gallery_exists',
      'error' => t('The custom gallery field must only contain lowercase letters, numbers, and underscores.'),
    ),
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][colorbox_gallery]"]' => array(
          'value' => 'custom',
        ),
      ),
    ),
  );
  $caption = array(
    'auto' => t('Automatic'),
    'title' => t('Title text'),
    'alt' => t('Alt text'),
    'node_title' => t('Content title'),
    'custom' => t('Custom (with tokens)'),
    'none' => t('None'),
  );
  $element['colorbox_caption'] = array(
    '#title' => t('Caption'),
    '#type' => 'select',
    '#default_value' => $settings['colorbox_caption'],
    '#options' => $caption,
    '#description' => t('Automatic will use the first none empty value of the title, the alt text and the content title.'),
  );
  $element['colorbox_caption_custom'] = array(
    '#title' => t('Custom caption'),
    '#type' => 'textfield',
    '#default_value' => $settings['colorbox_caption_custom'],
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array(
          'value' => 'custom',
        ),
      ),
    ),
  );

  // Allow users to hide or set a custom recursion limit.
  // The module token_tweaks sets a global recursion limit that can not be bypassed.
  if (module_exists('token') && ($recursion_limit = min(variable_get('token_tree_recursion_limit', 3), variable_get('colorbox_token_recursion_limit', 3)))) {
    $element['colorbox_token'] = array(
      '#type' => 'fieldset',
      '#title' => t('Replacement patterns'),
      '#theme' => 'token_tree',
      '#token_types' => array(
        $instance['entity_type'],
        'file',
      ),
      '#recursion_limit' => $recursion_limit,
      '#dialog' => TRUE,
      '#states' => array(
        'visible' => array(
          ':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array(
            'value' => 'custom',
          ),
        ),
      ),
    );
  }
  else {
    $element['colorbox_token'] = array(
      '#type' => 'fieldset',
      '#title' => t('Replacement patterns'),
      '#description' => '<strong class="error">' . t('For token support the <a href="@token_url">token module</a> must be installed.', array(
        '@token_url' => 'http://drupal.org/project/token',
      )) . '</strong>',
      '#states' => array(
        'visible' => array(
          ':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array(
            'value' => 'custom',
          ),
        ),
      ),
    );
  }
  return $element;
}