You are here

function simplecrop_field_widget_settings_form in SimpleCrop 7

Implements hook_field_widget_settings_form().

File

includes/simplecrop.field.inc, line 52
Contains information about field widget and related functions.

Code

function simplecrop_field_widget_settings_form($field, $instance) {
  $widget = $instance['widget'];
  $settings = $widget['settings'];

  // Use the image widget settings form.
  $form = image_field_widget_settings_form($field, $instance);

  // Disable preview functionality that comes from image widget,
  // but keep it in form to avoid php notices that element is missing.
  $form['preview_image_style']['#default_value'] = FALSE;
  $form['preview_image_style']['#access'] = FALSE;
  $form['simplecrop'] = array(
    '#type' => 'fieldset',
    '#title' => t('Simplecrop settings'),
    '#weight' => 15,
  );
  $form['simplecrop']['upload_display'] = array(
    '#type' => 'select',
    '#title' => t('What user should see after he uploaded new image?'),
    '#options' => array(
      SIMPLECROP_DISPLAY_ORIGINAL_IMAGE => t('Original image with crop selection'),
      SIMPLECROP_DISPLAY_CROPPED_IMAGE => t('Cropped image'),
    ),
    '#default_value' => $settings['simplecrop']['upload_display'],
    '#description' => t('Choose what should be displayed first right after new image was uploaded.'),
  );
  $form['simplecrop']['initial_display'] = array(
    '#type' => 'select',
    '#title' => t('What user should see initially when opens edit image form?'),
    '#options' => array(
      SIMPLECROP_DISPLAY_ORIGINAL_IMAGE => t('Original image with crop selection'),
      SIMPLECROP_DISPLAY_CROPPED_IMAGE => t('Cropped image'),
    ),
    '#default_value' => $settings['simplecrop']['initial_display'],
    '#description' => t('Choose what should be displayed when user opens content edit form with simplecrop image.'),
  );
  $form['simplecrop']['hide_filename'] = array(
    '#type' => 'checkbox',
    '#title' => t('Hide filename'),
    '#description' => t('Remove info about file name with its size from widget display.'),
    '#default_value' => $settings['simplecrop']['hide_filename'],
  );

  // Settings of source image and cropping area.
  $source_settings = $settings['simplecrop']['source'];
  $form['simplecrop']['source'] = array(
    '#type' => 'fieldset',
    '#title' => t('Original image settings'),
    '#description' => t('Settings of uploaded image where user selects cropping area.'),
  );
  $form['simplecrop']['source']['scale'] = array(
    '#type' => 'item',
    '#title' => t('Maximum resolution'),
    '#field_prefix' => '<div class="container-inline">',
    '#field_suffix' => '</div>',
    '#description' => t('Display of image resolution will be downscaled to the following values if uploaded image height or width is bigger that this value.'),
  );
  $form['simplecrop']['source']['scale']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Source image scale width'),
    '#title_display' => 'invisible',
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
    '#default_value' => $source_settings['scale']['width'],
    '#required' => TRUE,
    '#size' => 5,
    '#maxlength' => 5,
    '#field_suffix' => ' x ',
  );
  $form['simplecrop']['source']['scale']['height'] = array(
    '#type' => 'textfield',
    '#title' => t('Source image scale height'),
    '#title_display' => 'invisible',
    '#field_suffix' => t('pixels'),
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
    '#default_value' => $source_settings['scale']['height'],
    '#required' => TRUE,
    '#size' => 5,
    '#maxlength' => 5,
  );

  // Cropped image settings.
  $cropped_settings = !empty($settings['simplecrop']['cropped']) ? $settings['simplecrop']['cropped'] : array();
  $form['simplecrop']['cropped'] = array(
    '#type' => 'fieldset',
    '#title' => t('Cropped image settings'),
    '#description' => t('Settings of cropped image.'),
  );
  $form['simplecrop']['cropped']['scale'] = array(
    '#type' => 'item',
    '#title' => t('Maximum resolution'),
    '#field_prefix' => '<div class="container-inline">',
    '#field_suffix' => '</div>',
    '#description' => t('Maximum resolution of cropped image display. Resolution will be downscaled to the following values if crop area height or width is bigger that this value.'),
  );
  $form['simplecrop']['cropped']['scale']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Source image scale width'),
    '#title_display' => 'invisible',
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
    '#default_value' => $cropped_settings['scale']['width'],
    '#required' => TRUE,
    '#size' => 5,
    '#maxlength' => 5,
    '#field_suffix' => ' x ',
  );
  $form['simplecrop']['cropped']['scale']['height'] = array(
    '#type' => 'textfield',
    '#title' => t('Source image scale height'),
    '#title_display' => 'invisible',
    '#field_suffix' => t('pixels'),
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
    '#default_value' => $cropped_settings['scale']['height'],
    '#required' => TRUE,
    '#size' => 5,
    '#maxlength' => 5,
  );

  // Settings of crop area.
  $crop_settings = $settings['simplecrop']['crop'];
  $form['simplecrop']['crop'] = array(
    '#type' => 'fieldset',
    '#title' => t('Crop area settings'),
  );
  $form['simplecrop']['crop']['ratio'] = array(
    '#type' => 'item',
    '#title' => t('Aspect ratio'),
    '#field_prefix' => '<div class="container-inline">',
    '#field_suffix' => '</div>',
    '#description' => t('Aspect ratio of cropping area. Leave blank to omit fixed ratio. <br/> Example: "3 : 1". That means that width of cropping area must be 3 times bigger than height.'),
  );
  $form['simplecrop']['crop']['ratio']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Aspect ratio width'),
    '#title_display' => 'invisible',
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
    '#default_value' => $crop_settings['ratio']['width'],
    '#size' => 4,
    '#maxlength' => 4,
    '#field_suffix' => ':',
  );
  $form['simplecrop']['crop']['ratio']['height'] = array(
    '#type' => 'textfield',
    '#title' => t('Aspect ratio height'),
    '#title_display' => 'invisible',
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
    '#default_value' => $crop_settings['ratio']['height'],
    '#size' => 4,
    '#maxlength' => 4,
  );
  $areas = array(
    'min_area' => 'Minimum',
    'max_area' => 'Maximum',
  );
  foreach ($areas as $area => $name) {
    $form['simplecrop']['crop'][$area] = array(
      '#type' => 'item',
      '#title' => t('@area resolution of crop area', array(
        '@area' => $name,
      )),
      '#field_prefix' => '<div class="container-inline">',
      '#field_suffix' => '</div>',
      '#description' => t('@area width and height of crop area that user may select on image. Leave blank to skip this setting.', array(
        '@area' => $name,
      )) . '<br/>' . t('Important note: this limits apply to original image resolution. That means that if you original image will be scaled - these limits also will be scaled.'),
    );
    $form['simplecrop']['crop'][$area]['width'] = array(
      '#type' => 'textfield',
      '#title' => t('@area crop area width', array(
        '@area' => $name,
      )),
      '#title_display' => 'invisible',
      '#element_validate' => array(
        'element_validate_integer_positive',
      ),
      '#default_value' => $crop_settings[$area]['width'],
      '#size' => 5,
      '#maxlength' => 5,
      '#field_suffix' => ' x ',
    );
    $form['simplecrop']['crop'][$area]['height'] = array(
      '#type' => 'textfield',
      '#title' => t('@area crop area height', array(
        '@area' => $name,
      )),
      '#title_display' => 'invisible',
      '#element_validate' => array(
        'element_validate_integer_positive',
      ),
      '#default_value' => $crop_settings[$area]['height'],
      '#size' => 5,
      '#maxlength' => 5,
      '#field_suffix' => t('pixels'),
    );
  }
  $form['simplecrop']['crop']['initial_area'] = array(
    '#type' => 'select',
    '#title' => t('Initial crop area'),
    '#options' => array(
      SIMPLECROP_CROP_AREA_MINIMIZE => t('Minimize'),
      SIMPLECROP_CROP_AREA_MAXIMIZE => t('Maximize'),
      SIMPLECROP_CROP_AREA_NONE => t('Not selected'),
    ),
    '#default_value' => $crop_settings['initial_area'],
    '#description' => theme('item_list', array(
      'items' => array(
        t('Minimize - if minimum resolution of crop area is defined - then after upload image will have this area selected. Otherwise no area selection.'),
        t('Maximize - if maximum resolution of crop area is defined - then after upload image will have this area selected. Othewise complete image will be selected.'),
        t('Not selected - no default selection of uploaded image.'),
      ),
    )),
  );
  return $form;
}