diff -u b/src/Entity/Crop.php b/src/Entity/Crop.php --- b/src/Entity/Crop.php +++ b/src/Entity/Crop.php @@ -129,19 +129,8 @@ * {@inheritdoc} */ public static function findCrop($uri, $type) { - $query = \Drupal::database()->select('crop_field_data', 'cfd'); - $query->addField('cfd', 'cid'); - $query->condition('cfd.uri', $uri, 'LIKE'); - - if ($type) { - $query->condition('cfd.type', $type); - } - - $query->range(0, 1); - $crop = $query->execute() - ->fetchField(); - - return $crop ? \Drupal::entityTypeManager()->getStorage('crop')->load($crop) : NULL; + $cid = \Drupal::entityTypeManager()->getStorage('crop')->getCrop($uri, $type); + return $cid ? \Drupal::entityTypeManager()->getStorage('crop')->load($cid) : NULL; } /** only in patch2: unchanged: --- a/src/CropStorage.php +++ b/src/CropStorage.php @@ -5,8 +5,28 @@ namespace Drupal\crop; use Drupal\Core\Entity\Sql\SqlContentEntityStorage; /** - * Image crop storage class. + * Defines the storage handler class for image crop storage. + * + * This extends the Drupal\Core\Entity\Sql\SqlContentEntityStorage class, + * adding required special handling for comment entities. */ class CropStorage extends SqlContentEntityStorage implements CropStorageInterface { + /** + * {@inheritdoc} + */ + public function getCrop($uri, $type) { + $query = $this->database->select('crop_field_data', 'cfd'); + $query->addField('cfd', 'cid'); + $query->condition('cfd.uri', $uri, 'LIKE'); + + if ($type) { + $query->condition('cfd.type', $type); + } + + $query->range(0, 1); + + return $query->execute()->fetchField(); + } + } only in patch2: unchanged: --- a/src/CropStorageInterface.php +++ b/src/CropStorageInterface.php @@ -11,4 +11,17 @@ use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; */ interface CropStorageInterface extends SqlEntityStorageInterface, DynamicallyFieldableEntityStorageSchemaInterface, EntityBundleListenerInterface { + /** + * Retrieve crop ID based on image URI and crop type. + * + * @param string $uri + * URI of the image. + * @param string $type + * Crop type. + * + * @return int + * An integer represent crop id of given uri. + */ + public function getCrop($uri, $type); + }