function imageapi_optimize_form_image_style_validate in Image Optimize (or ImageAPI Optimize) 7.2
Form validation function for image_style_form().
We ensure that if our effect is present in the form it has the highest weight.
1 string reference to 'imageapi_optimize_form_image_style_validate'
File
- ./
imageapi_optimize.module, line 874
Code
function imageapi_optimize_form_image_style_validate($form, &$form_state) {
// Update the image style.
$style = $form_state['image_style'];
// Find the max of all the 'other' weights.
$weights = array();
$imageapi_optimize_effects_id = NULL;
if (!empty($form_state['values']['effects'])) {
foreach ($form_state['values']['effects'] as $ieid => $effect_data) {
if (isset($style['effects'][$ieid])) {
$effect = $style['effects'][$ieid];
if ($effect['name'] == 'imageapi_optimize') {
$imageapi_optimize_effects_id = $ieid;
}
else {
$weights[] = $effect_data['weight'];
}
}
}
}
// If the user is adding an effect, consider that too.
if ($form_state['triggering_element']['#value'] == $form['effects']['new']['add']['#value']) {
$weights[] = $form_state['values']['weight'];
}
if (isset($imageapi_optimize_effects_id) && !empty($weights)) {
form_set_value($form['effects'][$imageapi_optimize_effects_id]['weight'], max($weights) + 1, $form_state);
}
}