public static function Crop::getCropFromImageStyleId in Crop API 8.2
Retrieve crop from given image style.
Parameters
string $uri: URI of the image.
string $image_style_id: The image style id.
Return value
\Drupal\crop\CropInterface|null Crop entity used by effect 'crop_crop' or NULL if crop doesn't exist.
Overrides CropInterface::getCropFromImageStyleId
2 calls to Crop::getCropFromImageStyleId()
- Crop::getCropFromImageStyle in src/
Entity/ Crop.php - Retrieve crop from given image style.
- crop_file_url_alter in ./
crop.module - Implements hook_file_url_alter().
File
- src/
Entity/ Crop.php, line 160
Class
- Crop
- Defines the crop entity class.
Namespace
Drupal\crop\EntityCode
public static function getCropFromImageStyleId($uri, $image_style_id) {
$crop = NULL;
$effects = self::getEffectsFromImageStyleId($image_style_id);
if (isset($effects['crop_crop']['type'])) {
$crop = self::findCrop($uri, $effects['crop_crop']['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'];
// Image doesn't provide a crop, so we can ignore that provider.
if ($provider === 'image') {
continue;
}
$crop = self::findCrop($uri, $provider);
}
}
return $crop;
}