Media.php in Crop API 8
File
src/Plugin/Crop/EntityProvider/Media.php
View source
<?php
namespace Drupal\crop\Plugin\Crop\EntityProvider;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\crop\EntityProviderBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Media extends EntityProviderBase implements ContainerFactoryPluginInterface {
protected $entityTypeManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'));
}
public function uri(EntityInterface $entity) {
$bundle_entity_type = $entity
->getEntityType()
->getBundleEntityType();
$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;
}
$image = $this->entityTypeManager
->getStorage('file')
->load($entity->{$image_field}->target_id);
if (strpos($image
->getMimeType(), 'image') !== 0) {
return FALSE;
}
return $image
->getFileUri();
}
}
Classes
Name |
Description |
Media |
Media crop integration. |