You are here

function manualcrop_update_style_name in Manual Crop 7

Style form submit handler; Update the style name in the effect data and in the widgets.

1 string reference to 'manualcrop_update_style_name'
manualcrop_form_image_style_form_alter in ./manualcrop.admin.inc
Implements hook_form_FORM_ID_alter().

File

./manualcrop.admin.inc, line 540
Admin functionality for the Manual Crop module.

Code

function manualcrop_update_style_name($form, &$form_state) {
  $style = $form_state['image_style'];

  // Check if the style name should be updated.
  if (isset($form_state['values']['name']) && $style['name'] != $form_state['values']['name']) {
    if (!empty($style['effects'])) {
      $effect = reset($style['effects']);
      if (_manualcrop_is_own_effect($effect, TRUE)) {

        // Change the style name in the effect data and save it.
        $effect['data']['style_name'] = $form_state['values']['name'];
        image_effect_save($effect);

        // Update the crop selections.
        db_update('manualcrop')
          ->fields(array(
          'style_name' => $form_state['values']['name'],
        ))
          ->condition('style_name', $style['name'])
          ->execute();

        // Update the style name in the field widgets.
        _manualcrop_update_style_name_in_field_widget($style['name'], $form_state['values']['name']);
      }
    }

    // Update the style name in the image effects.
    _manualcrop_update_style_name_in_image_effect($style['name'], $form_state['values']['name']);
  }
}