You are here

function imagefield_crop_widget_settings in Imagefield Crop 5

Same name and namespace in other branches
  1. 6 imagefield_crop.module \imagefield_crop_widget_settings()

Implementation of hook_widget_settings().

File

./imagefield_crop.module, line 70

Code

function imagefield_crop_widget_settings($op, $widget) {
  switch ($op) {
    case 'callbacks':
      return array(
        'default value' => CONTENT_CALLBACK_CUSTOM,
      );
    case 'form':
      $form = array();
      $form['collapsible'] = array(
        '#type' => 'radios',
        '#title' => t('Collapsible behavior'),
        '#options' => array(
          1 => t('None.'),
          2 => t('Collapsible, expanded by default.'),
          3 => t('Collapsible, collapsed by default.'),
        ),
        '#default_value' => isset($widget['collapsible']) ? $widget['collapsible'] : 2,
      );
      $form['resolution'] = array(
        '#type' => 'textfield',
        '#title' => t('The resolution to crop the image onto'),
        '#default_value' => isset($widget['resolution']) ? $widget['resolution'] : '200x150',
        '#size' => 15,
        '#maxlength' => 10,
        '#description' => t('The output resolution of the cropped image, expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 not to rescale after cropping.'),
      );
      $form['enforce_ratio'] = array(
        '#type' => 'checkbox',
        '#title' => t('Enforce box crop box ratio'),
        '#default_value' => isset($widget['enforce_ratio']) ? $widget['enforce_ratio'] : 1,
        '#description' => t('Check this to force the ratio of the output on the crop box. NOTE: If you leave this unchecked, final images may be distorted'),
      );
      $form['croparea'] = array(
        '#type' => 'textfield',
        '#title' => t('The resolution of the cropping area'),
        '#default_value' => isset($widget['croparea']) ? $widget['croparea'] : '500x500',
        '#size' => 15,
        '#maxlength' => 10,
        '#description' => t('The resolution of the area used for the cropping of the image. Image will be scaled down to this size before cropping. Use WIDTHxHEIGHT format'),
      );
      $form['always_show'] = array(
        // REFACTOR: give a better name
        '#type' => 'checkbox',
        '#title' => t('Always show the cropping area'),
        '#default_value' => isset($widget['always_show']) ? $widget['always_show'] : 0,
        '#description' => t('Check this to show the cropping area even before the image is uploaded'),
      );
      $form['use_unscaled'] = array(
        '#type' => 'checkbox',
        '#title' => t('Use original (unscaled) image for cropping'),
        '#default_value' => isset($widget['use_unscaled']) ? $widget['use_unscaled'] : 1,
        '#description' => t('For better quality, use the original image for cropping, and not the one scaled for viewing'),
      );
      $form['image_path'] = array(
        '#type' => 'textfield',
        '#title' => t('Image path'),
        '#default_value' => $widget['image_path'] ? $widget['image_path'] : '',
        '#description' => t('Optional subdirectory within the "%dir" directory where images will be stored. Do not include trailing slash.', array(
          '%dir' => variable_get('file_directory_path', 'files'),
        )),
        '#after_build' => array(
          'imagefield_form_check_directory',
        ),
      );
      $form['custom_alt'] = array(
        '#type' => 'checkbox',
        '#title' => t('Enable custom alternate text'),
        '#default_value' => $widget['custom_alt'] ? $widget['custom_alt'] : 0,
        '#description' => t('Enable custom alternate text for images. Filename will be used if not checked.'),
      );
      $form['custom_title'] = array(
        '#type' => 'checkbox',
        '#title' => t('Enable custom title text'),
        '#default_value' => $widget['custom_title'] ? $widget['custom_title'] : 0,
        '#description' => t('Enable custom title text for images. Filename will be used if not checked.'),
      );
      return $form;
    case 'validate':
      list($rw, $rh) = explode('x', $widget['resolution']);
      if ($widget['enforce_ratio'] && (!is_numeric($rw) || intval($rw) != $rw || $rw <= 0 || !is_numeric($rh) || intval($rh) != $rh || $rh <= 0)) {
        form_set_error('resolution', t('Target resolution must be defined as WIDTHxHEIGHT if resolution is to be enforced'));
      }
      list($cw, $ch) = explode('x', $widget['croparea']);
      if (!is_numeric($cw) || intval($cw) != $cw || $cw <= 0 || !is_numeric($ch) || intval($ch) != $ch || $ch <= 0) {
        form_set_error('croparea', t('Crop area resolution must be defined as WIDTHxHEIGHT'));
      }
      _imagefield_crop_verify_gd();
      break;
    case 'save':
      return array(
        'collapsible',
        'resolution',
        'enforce_ratio',
        'croparea',
        'always_show',
        'use_unscaled',
        'image_path',
        'custom_alt',
        'custom_title',
      );
  }
}