You are here

public function ImageWidgetCropManager::deleteCrop in Image Widget Crop 8

Same name and namespace in other branches
  1. 8.2 src/ImageWidgetCropManager.php \Drupal\image_widget_crop\ImageWidgetCropManager::deleteCrop()

Delete the crop when user delete it.

Parameters

string $file_uri: Uri of image uploaded by user.

\Drupal\crop\Entity\CropType $crop_type: The CropType object.

int $file_id: Id of image uploaded by user.

2 calls to ImageWidgetCropManager::deleteCrop()
ImageWidgetCropManager::buildCropToEntity in src/ImageWidgetCropManager.php
Fetch all fields FileField and use "image_crop" element on an entity.
ImageWidgetCropManager::buildCropToForm in src/ImageWidgetCropManager.php
Fetch all form elements using image_crop element.

File

src/ImageWidgetCropManager.php, line 177

Class

ImageWidgetCropManager
ImageWidgetCropManager calculation class.

Namespace

Drupal\image_widget_crop

Code

public function deleteCrop($file_uri, CropType $crop_type, $file_id) {
  $image_styles = $this
    ->getImageStylesByCrop($crop_type
    ->id());
  $crop = $this->cropStorage
    ->loadByProperties([
    'type' => $crop_type
      ->id(),
    'uri' => $file_uri,
  ]);
  $this->cropStorage
    ->delete($crop);
  $this
    ->imageStylesOperations($image_styles, $file_uri);
  drupal_set_message(t('The crop "@cropType" was successfully deleted for image "@filename".', [
    '@cropType' => $crop_type
      ->label(),
    '@filename' => $this->fileStorage
      ->load($file_id)
      ->getFilename(),
  ]));
}