public function FocalPointManager::getCropEntity in Focal Point 8
Gets a crop entity for the given file.
If an existing crop entity is not found then a new one is created.
Parameters
\Drupal\file\FileInterface $file: File this focal point applies to.
string $crop_type: Crop type to be used.
Return value
\Drupal\crop\CropInterface Created crop entity.
Overrides FocalPointManagerInterface::getCropEntity
File
- src/
FocalPointManager.php, line 71
Class
- FocalPointManager
- Provides business logic related to focal point.
Namespace
Drupal\focal_pointCode
public function getCropEntity(FileInterface $file, $crop_type) {
if (Crop::cropExists($file
->getFileUri(), $crop_type)) {
/** @var \Drupal\crop\CropInterface $crop */
$crop = Crop::findCrop($file
->getFileUri(), $crop_type);
}
else {
$values = [
'type' => $crop_type,
'entity_id' => $file
->id(),
'entity_type' => 'file',
'uri' => $file
->getFileUri(),
];
$crop = $this->cropStorage
->create($values);
}
return $crop;
}