You are here

function picture_field_formatter_settings_form in Picture 7

Same name and namespace in other branches
  1. 7.2 picture.module \picture_field_formatter_settings_form()

Implements hook_field_formatter_settings_form().

File

./picture.module, line 394
Picture formatter.

Code

function picture_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $options = picture_get_mapping_options();
  if ($options) {
    $element['picture_group'] = array(
      '#title' => t('Picture group'),
      '#type' => 'select',
      '#default_value' => $settings['picture_group'],
      '#required' => TRUE,
      '#options' => $options,
    );
  }
  else {
    $element['picture_group'] = array(
      '#title' => t('Picture group'),
      '#type' => 'item',
      '#markup' => t('There are no picture groups defined. !create_link.', array(
        '!create_link' => l(t('Create a picture group'), 'admin/config/media/picture'),
      )),
    );
  }
  $image_styles = image_style_options(FALSE);
  $element['fallback_image_style'] = array(
    '#title' => t('Fallback image style'),
    '#type' => 'select',
    '#default_value' => $settings['fallback_image_style'],
    '#empty_option' => t('Automatic'),
    '#options' => $image_styles,
  );
  $link_types = picture_link_types($instance);
  $element['image_link'] = array(
    '#title' => t('Link image to'),
    '#type' => 'select',
    '#default_value' => $settings['image_link'],
    '#empty_option' => t('Nothing'),
    '#options' => $link_types,
    '#attributes' => array(
      'class' => array(
        'picture-image-link',
      ),
    ),
  );

  // Settings for the colorbox option.
  $element['colorbox_settings'] = array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
    '#title' => t('Colorbox settings'),
    '#collapsed' => FALSE,
    '#collapsible' => TRUE,
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings][image_link]"].picture-image-link' => array(
          'value' => 'colorbox',
        ),
      ),
    ),
  );
  $element['colorbox_settings']['colorbox_group'] = array(
    '#title' => t('Colorbox group'),
    '#type' => 'select',
    '#default_value' => $settings['colorbox_settings']['colorbox_group'],
    '#required' => FALSE,
    '#options' => picture_get_mapping_options(),
  );
  $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_settings']['colorbox_gallery'] = array(
    '#title' => t('Gallery (image grouping)'),
    '#type' => 'select',
    '#default_value' => $settings['colorbox_settings']['colorbox_gallery'],
    '#options' => $gallery,
    '#description' => t('How Colorbox should group the image galleries.'),
    '#attributes' => array(
      'class' => array(
        'picture-colorbox-gallery',
      ),
    ),
  );
  $element['colorbox_settings']['colorbox_gallery_custom'] = array(
    '#title' => t('Custom gallery'),
    '#type' => 'textfield',
    '#maxlength' => 32,
    '#default_value' => $settings['colorbox_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, hyphen and underscores.'),
    '#element_validate' => array(
      'colorbox_gallery_custom_validate',
    ),
    '#required' => FALSE,
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings][colorbox_settings][colorbox_gallery]"].picture-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_settings']['colorbox_caption'] = array(
    '#title' => t('Caption'),
    '#type' => 'select',
    '#default_value' => $settings['colorbox_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.'),
    '#attributes' => array(
      'class' => array(
        'picture-colorbox-caption',
      ),
    ),
  );
  $element['colorbox_settings']['colorbox_caption_custom'] = array(
    '#title' => t('Custom caption'),
    '#type' => 'textfield',
    '#default_value' => $settings['colorbox_settings']['colorbox_caption_custom'],
    '#states' => array(
      'visible' => array(
        ':input[name$="[settings][colorbox_settings][colorbox_caption]"].picture-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_settings']['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][colorbox_settings][colorbox_caption]"].picture-colorbox-caption' => array(
            'value' => 'custom',
          ),
        ),
      ),
    );
  }
  else {
    $element['colorbox_settings']['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][colorbox_settings][colorbox_caption]"].picture-colorbox-caption' => array(
            'value' => 'custom',
          ),
        ),
      ),
    );
  }
  return $element;
}