You are here

public function CropStorage::getCrop in Crop API 8

Same name and namespace in other branches
  1. 8.2 src/CropStorage.php \Drupal\crop\CropStorage::getCrop()

Retrieve crop ID based on image URI and crop type.

Parameters

string $uri: URI of the image.

string $type: Crop type.

Return value

\Drupal\crop\CropInterface|null A Crop object or NULL if nothing matches the search parameters.

Overrides CropStorageInterface::getCrop

File

src/CropStorage.php, line 18

Class

CropStorage
Defines the storage handler class for image crop storage.

Namespace

Drupal\crop

Code

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);
  $cid = $query
    ->execute()
    ->fetchField();
  return $cid ? $this
    ->load($cid) : NULL;
}