You are here

function imagecache_proportions_widget_settings_alter in Imagecache Proportions 6

Implements hook_widget_settings_alter().

File

./imagecache_proportions.module, line 38
CCK formatter for imagefields that allows the user to select between 3 different imagecache presets depending on the proportions of the original image uploaded. One preset would be squared for more or less squared images, another for wider images and…

Code

function imagecache_proportions_widget_settings_alter(&$settings, $op, $widget) {
  $widget_types = array(
    'imagefield_widget',
    'swfupload_widget',
    'image_fupload_imagefield_widget',
    'imagefield_crop_widget',
  );
  if (!empty($widget['type']) && in_array($widget['type'], $widget_types) || !empty($widget['widget_type']) && in_array($widget['widget_type'], $widget_types)) {
    switch ($op) {
      case 'form':
        $options = array(
          t('None'),
        );

        // get a list of all preset names for our form options
        foreach (imagecache_presets() as $id => $preset) {
          $options[$preset['presetname']] = $preset['presetname'];
        }
        $settings['imagecache_proportions'] = array(
          '#type' => 'fieldset',
          '#title' => t('Imagecache proportions'),
          '#collapsible' => TRUE,
          '#collapsed' => $collapsed,
          '#description' => t('Preset settings for imagecache proportions.'),
        );
        $settings['imagecache_proportions']['horizontal_preset'] = array(
          '#type' => 'select',
          '#title' => t('Select the horizontal preset'),
          '#description' => t('Preset used when the image is wider than higher.'),
          '#options' => $options,
          '#default_value' => $widget['horizontal_preset'],
        );
        $settings['imagecache_proportions']['vertical_preset'] = array(
          '#type' => 'select',
          '#title' => t('Select the vertical preset'),
          '#description' => t('Preset used when the image is higher than wider.'),
          '#options' => $options,
          '#default_value' => $widget['vertical_preset'],
        );
        $settings['imagecache_proportions']['squared_preset'] = array(
          '#type' => 'select',
          '#title' => t('Select the squared preset'),
          '#description' => t('Preset used when the image is equally wider and higher.'),
          '#options' => $options,
          '#default_value' => $widget['squared_preset'],
        );
        $settings['imagecache_proportions']['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' => $widget['looseness'],
        );
        $link_options = array(
          'none' => t('No link'),
          'node' => t('Link to node'),
          '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 (module_exists('thickbox')) {
          $link_options['thickbox'] = t('Modal window using thickbox');
        }
        if (module_exists('shadowbox')) {
          $link_options['shadowbox'] = t('Modal window using shadowbox');
        }
        if (module_exists('lightbox2')) {
          $link_options['lightbox2'] = t('Modal window using lightbox2');
        }
        $settings['imagecache_proportions']['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' => $widget['enable_link'],
        );
        break;
      case 'save':
        $settings[] = 'horizontal_preset';
        $settings[] = 'vertical_preset';
        $settings[] = 'squared_preset';
        $settings[] = 'looseness';
        $settings[] = 'enable_link';
        break;
    }
  }
}