use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\crop\CropInterface;
use Drupal\crop\EntityProviderNotFoundException;
+use Drupal\image\ImageStyleInterface;
/**
* Defines the crop entity class.
* "langcode" = "langcode",
* "uuid" = "uuid"
* },
+ * revision_metadata_keys = {
+ * "revision_timestamp" = "revision_timestamp",
+ * "revision_uid" = "revision_uid",
+ * "revision_log" = "revision_log"
+ * },
* bundle_entity_type = "crop_type",
* permission_granularity = "entity_type",
* admin_permission = "administer crop",
* {@inheritdoc}
*/
public static function findCrop($uri, $type) {
- $query = \Drupal::entityQuery('crop')
- ->condition('uri', $uri);
- if ($type) {
- $query->condition('type', $type);
+ return \Drupal::entityTypeManager()->getStorage('crop')->getCrop($uri, $type);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getCropFromImageStyle($uri, ImageStyleInterface $image_style) {
+ $effects = [];
+ $crop = FALSE;
+
+ foreach ($image_style->getEffects() as $uuid => $effect) {
+ // Store the effects parameters for later use.
+ $effects[$effect->getPluginId()] = [
+ 'uuid' => $uuid,
+ 'provider' => $effect->getPluginDefinition()['provider'],
+ ];
+ }
+
+ if (isset($effects['crop_crop']) && $image_style->getEffects()
+ ->has($effects['crop_crop']['uuid'])) {
+ $type = $image_style->getEffect($effects['crop_crop']['uuid'])
+ ->getConfiguration()['data']['crop_type'];
+ $crop = self::findCrop($uri, $type);
+ }
+
+ // Fallback to use the provider as a fallback to check if provider name,
+ // match with crop types for modules non-based on "manual crop" effects.
+ if (!$crop) {
+ foreach ($effects as $effect) {
+ $provider = $effect['provider'];
+ $crop = self::findCrop($uri, $provider);
+ }
}
- $crop = $query->sort('cid')
- ->range(0, 1)
- ->execute();
- return $crop ? \Drupal::entityTypeManager()->getStorage('crop')->load(current($crop)) : NULL;
+ return $crop;
}
/**
$fields['revision_timestamp'] = BaseFieldDefinition::create('created')
->setLabel(t('Revision timestamp'))
->setDescription(t('The time that the current revision was created.'))
- ->setQueryable(FALSE)
->setRevisionable(TRUE);
$fields['revision_uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Revision author ID'))
->setDescription(t('The user ID of the author of the current revision.'))
->setSetting('target_type', 'user')
- ->setQueryable(FALSE)
->setRevisionable(TRUE);
$fields['revision_log'] = BaseFieldDefinition::create('string_long')