You are here

function simplecrop_image_style_form_force_order in SimpleCrop 7

Submit handler for image effects form. Forces simplecrop effect to be the first in a list.

1 string reference to 'simplecrop_image_style_form_force_order'
simplecrop_form_image_style_form_alter in ./simplecrop.module
Implements hook_form_FORM_ID_alter().

File

./simplecrop.module, line 143
Contains main hook definitions for SimpleCrop module.

Code

function simplecrop_image_style_form_force_order($form, &$form_state) {
  $submitted_style = $form_state['image_style'];

  // Always reload image style to get actual info from other submit callbacks.
  $style = image_style_load($submitted_style['name'], $submitted_style['isid']);

  // Pick SimpleCrop effect and minimal weight of all effects.
  foreach ($style['effects'] as $effect) {
    if ($effect['module'] == 'simplecrop') {
      $simplecrop_effect = $effect;
    }
    if (!isset($min_weight) || $min_weight > $effect['weight']) {
      $min_weight = $effect['weight'];
    }
  }

  // Force simplecrop effect always to be the first in list.
  if (isset($simplecrop_effect) && isset($min_weight) && $simplecrop_effect['weight'] != $min_weight) {
    $simplecrop_effect['weight'] = $min_weight - 1;
    image_effect_save($simplecrop_effect);
    drupal_set_message(t('SimpleCrop effect was forced to be the first to prevent possible crop issues.'));
  }
}