Form builder; Form for adding and editing image effects.
This form is used universally for editing all image effects. Each effect adds its own custom section to the form by calling the 'form callback' specified in hook_image_effect_info().
$form_state: An associative array containing the current state of the form.
$style: An image style array.
$effect: An image effect array.
function image_effect_form($form, &$form_state, $style, $effect) {
// If there's no configuration for this image effect, return to
// the image style page.
if (!isset($effect['form callback'])) {
drupal_goto('admin/config/media/image-styles/manage/' . $style
->id());
}
$form_state['image_style'] = $style;
$form_state['image_effect'] = $effect;
if (!empty($effect['ieid'])) {
$title = t('Edit %label effect', array(
'%label' => $effect['label'],
));
}
else {
$title = t('Add %label effect', array(
'%label' => $effect['label'],
));
}
drupal_set_title($title, PASS_THROUGH);
$form['#attached']['css'][drupal_get_path('module', 'image') . '/css/image.admin.css'] = array();
$form['ieid'] = array(
'#type' => 'value',
'#value' => !empty($effect['ieid']) ? $effect['ieid'] : NULL,
);
$form['name'] = array(
'#type' => 'value',
'#value' => $effect['name'],
);
$form['data'] = call_user_func($effect['form callback'], $effect['data']);
$form['data']['#tree'] = TRUE;
// Check the URL for a weight, then the image effect, otherwise use default.
$form['weight'] = array(
'#type' => 'hidden',
'#value' => isset($_GET['weight']) ? intval($_GET['weight']) : (isset($effect['weight']) ? $effect['weight'] : count($style->effects)),
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => !empty($effect['ieid']) ? t('Update effect') : t('Add effect'),
);
$form['actions']['cancel'] = array(
'#type' => 'link',
'#title' => t('Cancel'),
'#href' => 'admin/config/media/image-styles/manage/' . $style
->id(),
);
return $form;
}