You are here

public function CropStorage::getCrop in Crop API 8.2

Same name and namespace in other branches
  1. 8 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 36

Class

CropStorage
Defines the storage handler class for image crop storage.

Namespace

Drupal\crop

Code

public function getCrop($uri, $type) {
  if (!isset($this->cropsByUri[$uri])) {
    $query = $this->database
      ->select('crop_field_data', 'cfd');
    $query
      ->fields('cfd', [
      'type',
      'cid',
    ]);
    $query
      ->condition('cfd.uri', $uri);
    $this->cropsByUri[$uri] = $query
      ->execute()
      ->fetchAllKeyed();
  }
  if (isset($this->cropsByUri[$uri][$type])) {
    return $this
      ->load($this->cropsByUri[$uri][$type]);
  }
  return NULL;
}