You are here

function galleryformatter_widget_settings_alter in Gallery formatter 6

Implementation of hook_widget_settings_alter().

Alters the imagefield widget so that any image field can be used as a gallery Inserts two new form elements for selecting the thumb imagecache preset and the slide imagecache preset in its own fieldset

File

./galleryformatter.module, line 11

Code

function galleryformatter_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'];
        }

        // only show collapsed if no selections have been made
        $collapsed = $widget['slide_preset'] == '0' && $widget['thumb_preset'] == '0';
        $settings['galleryformatter'] = array(
          '#type' => 'fieldset',
          '#title' => t('Gallery Formatter'),
          '#collapsible' => TRUE,
          '#collapsed' => $collapsed,
          '#description' => t('Setting <strong>both</strong> values below will trigger the gallery behaviour.') . '<p>' . t("Don't forget to set the <strong>Number of values</strong> to either <em>Unlimitted</em> or the maximum number of images each gallery could accept.") . '</p>',
        );
        $settings['galleryformatter']['slide_preset'] = array(
          '#type' => 'select',
          '#title' => t('Select the slide preset'),
          '#options' => $options,
          '#default_value' => $widget['slide_preset'],
          '#description' => t('Select the imagecache preset you would like to show when clicked on the thumbnail.'),
        );
        $settings['galleryformatter']['thumb_preset'] = array(
          '#type' => 'select',
          '#title' => t('Select the thumbnail preset'),
          '#options' => $options,
          '#default_value' => $widget['thumb_preset'],
          '#description' => t('Select the imagecache preset you would like to show for the thumbnails list.'),
        );
        $style_options = array();
        $styles = module_invoke_all('galleryformatter_styles');

        // The keys used for options must be valid html id-s.
        foreach ($styles as $style) {
          $style_options[$style] = $style;
        }
        ksort($style_options);
        $settings['galleryformatter']['style'] = array(
          '#type' => 'select',
          '#title' => t('Style'),
          '#options' => array(
            'nostyle' => t('No style'),
          ) + $style_options,
          '#default_value' => isset($widget['style']) ? $widget['style'] : 'default',
          '#description' => t('Choose the gallery style.'),
        );
        $settings['galleryformatter']['link_to_full'] = array(
          '#type' => 'checkbox',
          '#title' => t('Link slides to the full image'),
          '#default_value' => $widget['link_to_full'],
          '#description' => t('If you check this on, the slides will be linked to the preset you choose in <em>Select the full image preset</em> below.'),
        );
        $options[0] = t('None (original image)');
        $settings['galleryformatter']['link_to_full_preset'] = array(
          '#type' => 'select',
          '#title' => t('Select the full image preset'),
          '#options' => $options,
          '#default_value' => $widget['link_to_full_preset'],
          '#description' => t('Select the imagecache preset you would like to show when clicked on the thumbnail.<br />If you select none, the the link will point to the original image.'),
        );
        $options = array();

        // integration with other modules for jQuery modal windows
        if (module_exists('colorbox')) {
          $options['colorbox'] = 'colorbox';
        }
        if (module_exists('thickbox')) {
          $options['thickbox'] = 'thickbox';
        }
        if (module_exists('shadowbox')) {
          $options['shadowbox'] = 'shadowbox';
        }
        if (module_exists('lightbox2')) {
          $options['lightbox2'] = 'lightbox2';
        }
        $options['none'] = t('Do not use modal');
        $settings['galleryformatter']['modal'] = array(
          '#type' => 'select',
          '#title' => t('Use jQuery modal for full image link'),
          '#options' => $options,
          '#default_value' => $widget['modal'],
          '#description' => t("Select which jQuery modal module you'd like to display the full link image in, if any."),
        );
        break;
      case 'save':
        $settings[] = 'slide_preset';
        $settings[] = 'thumb_preset';
        $settings[] = 'style';
        $settings[] = 'link_to_full';
        $settings[] = 'link_to_full_preset';
        $settings[] = 'modal';
        break;
    }
  }
}