- $entity = $form_state->getFormObject()->getEntity();
- $form_state_values = $form_state->getValues();
- if (is_array($form_state_values['image_crop']) && isset($form_state_values['image_crop']['crop_wrapper'])) {
- // Parse all values and get properties associate with the crop type.
- foreach ($form_state_values['image_crop']['crop_wrapper'] as $crop_type_name => $properties) {
- $properties = $properties['crop_container']['values'];
- /** @var \Drupal\crop\Entity\CropType $crop_type */
- $crop_type = $this->cropTypeStorage->load($crop_type_name);
-
- // If the crop type needed is disabled or delete.
- if (empty($crop_type) && $crop_type instanceof CropType) {
- drupal_set_message(t("The CropType ('@cropType') is not active or not defined. Please verify configuration of image style or ImageWidgetCrop formatter configuration", ['@cropType' => $crop_type->id()]), 'error');
- return;
- }
-
- if (is_array($properties) && isset($properties)) {
- $crop_exists = Crop::cropExists($entity->getFileUri(), $crop_type_name);
- if (!$crop_exists) {
- if ($properties['crop_applied'] == '1' && isset($properties) && (!empty($properties['width']) && !empty($properties['height']))) {
- $this->applyCrop($properties, $form_state_values['image_crop'], $crop_type);
- }
+ if ($entity = $form_state->getFormObject()->getEntity()) {
+ $form_state_values = $form_state->getValues();
+ // @TODO Do not hardcode key of element to "image_crop" check #type of element instead like \Drupal\Core\Form\FormBuilder::doBuildForm.
+ if (is_array($form_state_values['image_crop']) && isset($form_state_values['image_crop']['crop_wrapper'])) {
+ // Parse all values and get properties associate with the crop type.
+ foreach ($form_state_values['image_crop']['crop_wrapper'] as $crop_type_name => $properties) {
+ $properties = $properties['crop_container']['values'];
+ /** @var \Drupal\crop\Entity\CropType $crop_type */
+ $crop_type = $this->cropTypeStorage->load($crop_type_name);
+
+ // If the crop type needed is disabled or delete.
+ if (empty($crop_type) && $crop_type instanceof CropType) {
+ drupal_set_message(t("The CropType ('@cropType') is not active or not defined. Please verify configuration of image style or ImageWidgetCrop formatter configuration", ['@cropType' => $crop_type->id()]), 'error');
+ return;