You are here

function exif_orientation_field_widget_form_alter in EXIF Orientation 8

Implements hook_field_widget_form_alter().

Add a custom validator before file_validate_image_resolution(). file_validate_image_resolution resizes the image if it's too large losing the exif data in the process.

File

./exif_orientation.module, line 27
Module file for EXIF Orientation.

Code

function exif_orientation_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
  if (isset($element['#upload_validators']['file_validate_image_resolution'])) {
    $element['#upload_validators'] = [
      'exif_orientation_validate_image_rotation' => [],
    ] + $element['#upload_validators'];
  }
}