You are here

function colorbox_field_formatter_field_formatter_settings_form in Colorbox field formatter 7

Implements hook_field_formatter_settings_form().

File

./colorbox_field_formatter.module, line 69
Implement a colorbox field formatter for proper links.

Code

function colorbox_field_formatter_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $settings = $instance['display'][$view_mode]['settings'];
  $element = array();
  $styles = _colorbox_field_formatter_get_styles();
  $style_keys = array_keys($styles);
  $default_style = array_pop($style_keys);
  if ($field['type'] == 'image') {
    $image_styles = image_style_options(FALSE);
    $image_styles['hide'] = t('Hide (do not display image)');
    $element['colorbox_field_formatter_image_style'] = array(
      '#title' => t('Content image style'),
      '#type' => 'select',
      '#default_value' => empty($settings['colorbox_field_formatter_image_style']) ? '' : $settings['colorbox_field_formatter_image_style'],
      '#empty_option' => t('None (original image)'),
      '#options' => $image_styles,
      '#description' => t('Image style to use in the content.'),
    );
  }
  $element['colorbox_field_formatter_style'] = array(
    '#title' => t('Style of colorbox'),
    '#type' => 'select',
    '#default_value' => !empty($settings['colorbox_field_formatter_style']) ? $settings['colorbox_field_formatter_style'] : $default_style,
    '#options' => $styles,
  );
  $element['colorbox_field_formatter_link_type'] = array(
    '#title' => t('Link colorbox to'),
    '#type' => 'select',
    '#default_value' => $settings['colorbox_field_formatter_link_type'],
    '#options' => _colorbox_field_formatter_get_link_types(),
    '#attributes' => array(
      'class' => array(
        'colorbox-field-formatter-link-type',
      ),
    ),
  );
  $element['colorbox_field_formatter_link'] = array(
    '#title' => t('URI'),
    '#type' => 'textfield',
    '#default_value' => $settings['colorbox_field_formatter_link'],
    '#states' => array(
      'visible' => array(
        'select.colorbox-field-formatter-link-type' => array(
          'value' => 'manual',
        ),
      ),
    ),
  );
  if (module_exists('token')) {
    $element['token_help_wrapper'] = array(
      '#type' => 'container',
      '#states' => array(
        'visible' => array(
          'select.colorbox-field-formatter-link-type' => array(
            'value' => 'manual',
          ),
        ),
      ),
    );
    $element['token_help_wrapper']['token_help'] = array(
      '#theme' => 'token_tree',
      '#token_types' => array(
        'entity' => $form['#entity_type'],
      ),
      '#global_types' => FALSE,
    );
  }
  $element['colorbox_field_formatter_width'] = array(
    '#title' => t('Width'),
    '#type' => 'textfield',
    '#default_value' => $settings['colorbox_field_formatter_width'],
  );
  $element['colorbox_field_formatter_height'] = array(
    '#title' => t('Height'),
    '#type' => 'textfield',
    '#default_value' => $settings['colorbox_field_formatter_height'],
  );
  $element['colorbox_field_formatter_iframe'] = array(
    '#title' => t('iFrame Mode'),
    '#type' => 'checkbox',
    '#default_value' => $settings['colorbox_field_formatter_iframe'],
  );
  $element['colorbox_field_formatter_anchor'] = array(
    '#title' => t('Anchor'),
    '#type' => 'textfield',
    '#default_value' => $settings['colorbox_field_formatter_anchor'],
    '#description' => t('This can be used with the "inline" style by entering the ID (without the leading "#") of the inline content to colorbox.'),
  );
  $element['colorbox_field_formatter_class'] = array(
    '#title' => t('Class'),
    '#type' => 'textfield',
    '#default_value' => $settings['colorbox_field_formatter_class'],
  );
  $element['colorbox_field_formatter_rel'] = array(
    '#title' => t('Rel'),
    '#type' => 'textfield',
    '#default_value' => empty($settings['colorbox_field_formatter_rel']) ? '' : $settings['colorbox_field_formatter_rel'],
    '#description' => t('This can be used to identify a group for Colorbox to cycle through.'),
  );
  return $element;
}