You are here

function imagecache_proportions_field_formatter_settings_form in Imagecache Proportions 7

Implements hook_field_formatter_settings_form().

File

./imagecache_proportions.module, line 49
Field formatter for image fields that allows the user to select between 3 different image styles depending on the proportions of the original image uploaded. One style would be squared for more or less squared images, another for wider images and the…

Code

function imagecache_proportions_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $form = array();
  $options = array(
    t('None'),
  );

  // get a list of all styles for our form options
  foreach (image_styles() as $id => $style) {
    $options[$id] = $id;
  }
  $form['horizontal_preset'] = array(
    '#type' => 'select',
    '#title' => t('Select the horizontal style'),
    '#description' => t('Style used when the image is wider than higher.'),
    '#options' => $options,
    '#default_value' => $settings['horizontal_preset'],
  );
  $form['vertical_preset'] = array(
    '#type' => 'select',
    '#title' => t('Select the vertical style'),
    '#description' => t('Style used when the image is higher than wider.'),
    '#options' => $options,
    '#default_value' => $settings['vertical_preset'],
  );
  $form['squared_preset'] = array(
    '#type' => 'select',
    '#title' => t('Select the squared style'),
    '#description' => t('Style used when the image is equally wider and higher.'),
    '#options' => $options,
    '#default_value' => $settings['squared_preset'],
  );
  $form['looseness'] = array(
    '#type' => 'textfield',
    '#size' => 10,
    '#title' => t('Select the looseness to consider an image squared'),
    '#description' => t('Number of pixels that a image can be wider than higher (or viceversa) to be considered squared.'),
    '#default_value' => $settings['looseness'],
  );
  $link_options = array(
    'none' => t('No link'),
    'entity' => t('Link to the entity (e.g node, taxonomy term...)'),
    'image' => t('Link to image'),
  );

  // If some fancy modal-lightbox module exists, we allow the user to select it.
  if (module_exists('colorbox')) {
    $link_options['colorbox'] = t('Modal window using colorbox');
  }

  // If some fancy modal-lightbox module exists, we allow the user to select it.
  if (module_exists('shadowbox')) {
    $link_options['shadowbox'] = t('Modal window using shadowbox');
  }
  $form['enable_link'] = array(
    '#type' => 'select',
    '#title' => t('Select the type of link of the image'),
    '#description' => t('Type of link of the image, if image selected and one of the js image popups is enabled (colorbox, shadowbox, lightbox2...) the image will open in a popup.'),
    '#options' => $link_options,
    '#default_value' => $settings['enable_link'],
  );
  if (module_exists('shadowbox')) {
    $form['shadowbox'] = array(
      '#type' => 'fieldset',
      '#title' => t('Shadowbox options'),
      '#states' => array(
        'visible' => array(
          ':input[name$="[settings_edit_form][settings][enable_link]"]' => array(
            'value' => 'shadowbox',
          ),
        ),
      ),
    );
    $form['shadowbox'] += imagecache_proportions_shadowbox_form($field, $instance, $view_mode, $form, $form_state);
  }
  if (module_exists('colorbox')) {
    $form['colorbox'] = array(
      '#type' => 'fieldset',
      '#title' => t('Colorbox options'),
      '#states' => array(
        'visible' => array(
          ':input[name$="[settings_edit_form][settings][enable_link]"]' => array(
            'value' => 'colorbox',
          ),
        ),
      ),
    );
    $form['colorbox'] += imagecache_proportions_colorbox_form($field, $instance, $view_mode, $form, $form_state);
  }
  return $form;
}