function imagefield_crop_field_widget_settings_form in Imagefield Crop 7.2
Same name and namespace in other branches
- 7.3 imagefield_crop.module \imagefield_crop_field_widget_settings_form()
- 7 imagefield_crop.module \imagefield_crop_field_widget_settings_form()
Implements hook_field_widget_settings_form().
File
- ./
imagefield_crop.module, line 454 - Functionality and Drupal hook implementations for the Imagefield Crop module.
Code
function imagefield_crop_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);
$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' => $settings['collapsible'],
);
// Resolution settings.
$resolution = explode('x', $settings['resolution']) + array(
'',
'',
);
$form['resolution'] = array(
'#title' => t('The resolution to crop the image onto'),
'#element_validate' => array(
'_image_field_resolution_validate',
),
'#theme_wrappers' => array(
'form_element',
),
'#description' => t('The output resolution of the cropped image, expressed as WIDTHxHEIGHT (e.g. 640x480). Leave blank to skip rescale after cropping. Note: output resolution must be defined in order to present a dynamic preview.'),
);
$form['resolution']['x'] = array(
'#type' => 'textfield',
'#default_value' => $resolution[0],
'#size' => 5,
'#maxlength' => 5,
'#field_suffix' => ' x ',
'#theme_wrappers' => array(),
);
$form['resolution']['y'] = array(
'#type' => 'textfield',
'#default_value' => $resolution[1],
'#size' => 5,
'#maxlength' => 5,
'#field_suffix' => ' ' . t('pixels'),
'#theme_wrappers' => array(),
);
$form['validate_resolution'] = array(
'#type' => 'checkbox',
'#title' => t('Validate minimum resolution'),
'#default_value' => $settings['validate_resolution'],
'#description' => t('If output resolution is set, but validation is disabled then images with smaller dimensions won\'t be cropped.'),
'#states' => array(
'invisible' => array(
'input[name="instance[widget][settings][resolution][x]"]' => array(
'value' => '',
),
'input[name="instance[widget][settings][resolution][y]"]' => array(
'value' => '',
),
),
),
);
$form['select_maximum_area'] = array(
'#type' => 'checkbox',
'#title' => t('Select maximum possible area'),
'#default_value' => $settings['select_maximum_area'],
'#description' => t('If checked, widget will select maximum area on the image and then resize it to output resolution.'),
'#states' => array(
'invisible' => array(
'input[name="instance[widget][settings][resolution][x]"]' => array(
'value' => '',
),
'input[name="instance[widget][settings][resolution][y]"]' => array(
'value' => '',
),
),
),
);
$form['enforce_ratio'] = array(
'#type' => 'checkbox',
'#title' => t('Enforce crop box ratio'),
'#default_value' => $settings['enforce_ratio'],
'#description' => t('Check this to force the ratio of the output on the crop box. NOTE: If you leave this unchecked but enforce an output resolution, the final image might be distorted'),
'#element_validate' => array(
'_imagefield_crop_widget_enforce_ratio_validate',
),
);
$custom_ratio = explode('x', $settings['custom_ratio']) + array(
'',
'',
);
$form['custom_ratio'] = array(
'#type' => 'container',
'#title' => t('Custom ratio'),
'#element_validate' => array(
'_image_field_resolution_validate',
'_imagefield_crop_widget_custom_ratio_validate',
),
'#theme_wrappers' => array(
'form_element',
),
'#description' => t('Ratio for crop area. For example 4:3 or 16:9 as width to height.'),
'#markup' => '',
'#states' => array(
'visible' => array(
'input[name="instance[widget][settings][resolution][x]"]' => array(
'value' => '',
),
'input[name="instance[widget][settings][resolution][y]"]' => array(
'value' => '',
),
'input[name="instance[widget][settings][enforce_ratio]"]' => array(
'checked' => TRUE,
),
),
),
);
$form['custom_ratio']['x'] = array(
'#type' => 'textfield',
'#default_value' => $custom_ratio[0],
'#size' => 5,
'#maxlength' => 5,
'#field_suffix' => ' x ',
'#theme_wrappers' => array(),
);
$form['custom_ratio']['y'] = array(
'#type' => 'textfield',
'#default_value' => $custom_ratio[1],
'#size' => 5,
'#maxlength' => 5,
'#field_suffix' => ' ' . t('pixels'),
'#theme_wrappers' => array(),
);
$form['enforce_minimum'] = array(
'#type' => 'checkbox',
'#title' => t('Enforce minimum crop size based on the output size'),
'#default_value' => $settings['enforce_minimum'],
'#description' => t('Check this to force a minimum cropping selection equal to the output size. NOTE: If you leave this unchecked you might get zoomed pixels if the cropping area is smaller than the output resolution.'),
'#element_validate' => array(
'_imagefield_crop_widget_enforce_minimum_validate',
),
);
// Crop area settings.
$croparea = explode('x', $settings['croparea']) + array(
'',
'',
);
$form['croparea'] = array(
'#title' => t('The resolution of the cropping area'),
'#element_validate' => array(
'_imagefield_crop_widget_croparea_validate',
),
'#theme_wrappers' => array(
'form_element',
),
'#description' => t('The resolution of the area used for the cropping of the image. Image will displayed at this resolution for cropping. Use WIDTHxHEIGHT format, empty or zero values are permitted, e.g. 500x will limit crop box to 500 pixels width.'),
);
$form['croparea']['x'] = array(
'#type' => 'textfield',
'#default_value' => $croparea[0],
'#size' => 5,
'#maxlength' => 5,
'#field_suffix' => ' x ',
'#theme_wrappers' => array(),
);
$form['croparea']['y'] = array(
'#type' => 'textfield',
'#default_value' => $croparea[1],
'#size' => 5,
'#maxlength' => 5,
'#field_suffix' => ' ' . t('pixels'),
'#theme_wrappers' => array(),
);
$form['gif_processing'] = array(
'#type' => 'radios',
'#title' => t('Gif files processing'),
'#options' => array(
'convert' => t('Convert into jpeg and resize'),
'skip' => t('Do not resize'),
),
'#default_value' => $settings['gif_processing'],
);
/* Introduce different setting for preview box.
* Width of the box should be defined, rather than image style,
* as its proportions are already defined by "resolution" of the cropping.
*/
unset($form['preview_image_style']);
$form['preview_image_width'] = array(
'#title' => t('Preview box width'),
'#type' => 'textfield',
'#default_value' => $settings['preview_image_width'],
'#size' => 5,
'#maxlength' => 5,
'#field_suffix' => ' ' . t('pixels'),
'#weight' => 15,
'#description' => t('Scale cropped image to a given width for preview.'),
);
return $form;
}