You are here

function image_settings_sizes_submit in Image 5.2

Same name and namespace in other branches
  1. 5 image.module \image_settings_sizes_submit()

Make changes to the settings before passing them off to system_settings_form_submit().

Remove deleted sizes, and use the label as indexes for new sizes.

File

./image.module, line 197

Code

function image_settings_sizes_submit($form_id, &$form_values) {
  $old_sizes = image_get_sizes();

  // If the size's operation, or dimensions change we need to rebuild.
  $rebuild = FALSE;
  foreach ($form_values['image_sizes'] as $key => $size) {

    // Changed to the original setting only affect new images and they
    // shouldn't be able to add or remove it.
    if ($key == IMAGE_ORIGINAL) {
      continue;
    }

    // Remove sizes without labels.
    if (empty($size['label'])) {
      unset($form_values['image_sizes'][$key]);
    }

    // Check if only one is set, indicating an addition or removal.
    if (isset($form_values['image_sizes'][$key]) ^ isset($old_sizes[$key])) {
      $rebuild |= TRUE;

      // When adding a new size, we need to assign a key.
      if (isset($form_values['image_sizes'][$key])) {
        unset($form_values['image_sizes'][$key]);
        $new_key = drupal_strtolower(drupal_substr($size['label'], 0, 32));
        $form_values['image_sizes'][$new_key] = $size;
      }
    }
    else {
      if (isset($form_values['image_sizes'][$key]) && isset($old_sizes[$key])) {

        // Did the operation, height or width change?
        foreach (array(
          'operation',
          'height',
          'width',
        ) as $field) {
          $rebuild |= $form_values['image_sizes'][$key][$field] != $old_sizes[$key][$field];
        }
      }
    }
  }

  // If we've changed anything update the image_update variable so the
  // derivative images are rebuilt.
  if ($rebuild) {
    drupal_set_message(t('Changes to the images sizes mean that the derivative images will need to be regenerated.'));
    $form_values['image_updated'] = time();
  }
  return system_settings_form_submit($form_id, $form_values);
}