function imagefield_crop_preset_form in Imagefield Crop 7.3
Implements form builder imagefield_crop_preset_form().
_state
Parameters
$form:
$preset:
Return value
array
1 string reference to 'imagefield_crop_preset_form'
- imagefield_crop_menu in ./
imagefield_crop.module - Implements hook_menu().
File
- ./
imagefield_crop.module, line 1011
Code
function imagefield_crop_preset_form($form, $form_state, $preset = array()) {
$form = array();
if (!empty($preset)) {
$form_state['preset'] = $preset;
if (empty($preset->label)) {
$preset->label = $preset->name;
}
}
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#default_value' => !empty($preset->label) ? $preset->label : '',
'#required' => TRUE,
);
if (empty($preset)) {
$form['name'] = array(
'#type' => 'machine_name',
'#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
'#size' => '64',
'#required' => TRUE,
'#machine_name' => array(
'exists' => 'imagefield_crop_preset_load_by_name',
'source' => array(
'label',
),
'replace_pattern' => '[^0-9a-z_\\-]',
'error' => t('Please only use lowercase alphanumeric characters, underscores (_), and hyphens (-) for preset names.'),
),
);
}
$form['preset'] = array(
'#type' => 'container',
'#markup' => '',
'#tree' => TRUE,
);
$form['preset']['crop-type'] = array(
'#type' => 'radios',
'#default_value' => !empty($preset->data['crop-type']) ? $preset->data['crop-type'] : 'resolution',
'#options' => array(
'resolution' => t('Fixed resolution'),
'ratio' => t('Ratio'),
),
'#title' => t('Crop type'),
);
// Resolution settings.
$form['preset']['resolution'] = array(
'#tree' => TRUE,
'#title' => t('The resolution to crop the image onto'),
'#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.'),
'#markup' => '',
'#states' => array(
'visible' => array(
'input[name="preset[crop-type]"]' => array(
'value' => 'resolution',
),
),
'invisible' => array(
'input[name="preset[crop-type]"]' => array(
'value' => 'ratio',
),
),
),
);
$form['preset']['resolution']['width'] = array(
'#type' => 'textfield',
'#default_value' => !empty($preset->data['resolution']['width']) ? $preset->data['resolution']['width'] : '',
'#size' => 5,
'#maxlength' => 5,
'#field_suffix' => ' x ',
'#theme_wrappers' => array(),
);
$form['preset']['resolution']['height'] = array(
'#type' => 'textfield',
'#default_value' => !empty($preset->data['resolution']['height']) ? $preset->data['resolution']['height'] : '',
'#size' => 5,
'#maxlength' => 5,
'#field_suffix' => ' ' . t('pixels'),
'#theme_wrappers' => array(),
);
$form['preset']['ratio'] = array(
'#type' => 'container',
'#title' => t('Custom ratio'),
'#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="preset[crop-type]"]' => array(
'value' => 'ratio',
),
),
'invisible' => array(
'input[name="preset[crop-type]"]' => array(
'value' => 'resolution',
),
),
),
);
$form['preset']['ratio']['width'] = array(
'#type' => 'textfield',
'#default_value' => !empty($preset->data['ratio']['width']) ? $preset->data['ratio']['width'] : '',
'#size' => 5,
'#maxlength' => 5,
'#field_suffix' => ' x ',
'#theme_wrappers' => array(),
);
$form['preset']['ratio']['height'] = array(
'#type' => 'textfield',
'#default_value' => !empty($preset->data['ratio']['height']) ? $preset->data['ratio']['height'] : '',
'#size' => 5,
'#maxlength' => 5,
'#field_suffix' => ' ' . t('pixels'),
'#theme_wrappers' => array(),
);
$form['preset']['min-resolution'] = array(
'#type' => 'container',
'#title' => t('Minimal result resolution'),
'#theme_wrappers' => array(
'form_element',
),
'#description' => t('Minimal resolution of result image.(e.g. 640x480).'),
'#markup' => '',
'#states' => array(
'visible' => array(
'input[name="preset[crop-type]"]' => array(
'value' => 'ratio',
),
),
'invisible' => array(
'input[name="preset[crop-type]"]' => array(
'value' => 'resolution',
),
),
),
);
$form['preset']['min-resolution']['width'] = array(
'#type' => 'textfield',
'#default_value' => !empty($preset->data['min-resolution']['width']) ? $preset->data['min-resolution']['width'] : '',
'#size' => 5,
'#maxlength' => 5,
'#field_suffix' => ' x ',
'#theme_wrappers' => array(),
);
$form['preset']['min-resolution']['height'] = array(
'#type' => 'textfield',
'#default_value' => !empty($preset->data['min-resolution']['height']) ? $preset->data['min-resolution']['height'] : '',
'#size' => 5,
'#maxlength' => 5,
'#field_suffix' => ' ' . t('pixels'),
'#theme_wrappers' => array(),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#submit' => array(
'imagefield_crop_preset_form_submit',
),
);
return $form;
}