public function Media::uri in Crop API 8.2
Same name and namespace in other branches
- 8 src/Plugin/Crop/EntityProvider/Media.php \Drupal\crop\Plugin\Crop\EntityProvider\Media::uri()
Gets URI of the image file.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: Entity being cropping.
Return value
string|false URI as string or FALSE
Overrides EntityProviderBase::uri
File
- src/
Plugin/ Crop/ EntityProvider/ Media.php, line 61
Class
- Media
- Media crop integration.
Namespace
Drupal\crop\Plugin\Crop\EntityProviderCode
public function uri(EntityInterface $entity) {
$bundle_entity_type = $entity
->getEntityType()
->getBundleEntityType();
/** @var \Drupal\Core\Config\Entity\ConfigEntityBase $entity_type */
$entity_type = $this->entityTypeManager
->getStorage($bundle_entity_type)
->load($entity
->bundle());
$image_field = $entity_type
->getThirdPartySetting('crop', 'image_field');
if ($entity->{$image_field}
->first()
->isEmpty()) {
return FALSE;
}
/** @var \Drupal\file\FileInterface $image */
$image = $this->entityTypeManager
->getStorage('file')
->load($entity->{$image_field}->target_id);
if (strpos($image
->getMimeType(), 'image') !== 0) {
return FALSE;
}
return $image
->getFileUri();
}