public function getImageVariation($imageId, $variationIdentifier)
{
$idArray = explode('-', $imageId);
if (count($idArray) != 2) {
throw new Exceptions\NotFoundException("Invalid image ID {$imageId}");
}
list($contentId, $fieldId) = $idArray;
$content = $this->repository->getContentService()->loadContent($contentId);
$fieldFound = false;
/** @var $field \eZ\Publish\API\Repository\Values\Content\Field */
foreach ($content->getFields() as $field) {
if ($field->id == $fieldId) {
$fieldFound = true;
break;
}
}
if (!$fieldFound) {
throw new Exceptions\NotFoundException("No image field with ID {$fieldId} could be found");
}
// check the field's value
if ($field->value->uri === null) {
throw new Exceptions\NotFoundException("Image file {$field->value->id} doesn't exist");
}
$versionInfo = $this->repository->getContentService()->loadVersionInfo($content->contentInfo);
try {
$variation = $this->imageVariationHandler->getVariation($field, $versionInfo, $variationIdentifier);
if ($content->contentInfo->mainLocationId === null) {
return $variation;
} else {
return new CachedValue($variation, array('locationId' => $content->contentInfo->mainLocationId));
}
} catch (InvalidVariationException $e) {
throw new Exceptions\NotFoundException("Invalid image variation {$variationIdentifier}");
}
}