-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZEE-3281: Variations are now returned for imageasset field type
- Loading branch information
Showing
6 changed files
with
333 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/lib/FieldTypeProcessor/ImageAssetFieldTypeProcessor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformRest\FieldTypeProcessor; | ||
|
||
use eZ\Publish\API\Repository\ContentService; | ||
use EzSystems\EzPlatformRest\FieldTypeProcessor; | ||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
class ImageAssetFieldTypeProcessor extends FieldTypeProcessor | ||
{ | ||
/** @var \Symfony\Component\Routing\RouterInterface */ | ||
private $router; | ||
|
||
/** @var \eZ\Publish\API\Repository\ContentService */ | ||
private $contentService; | ||
|
||
/** @var string[] */ | ||
private $configMappings; | ||
|
||
/** @var string[] */ | ||
private $variations; | ||
|
||
public function __construct( | ||
RouterInterface $router, | ||
ContentService $contentService, | ||
array $configMappings, | ||
array $variations | ||
) { | ||
$this->router = $router; | ||
$this->variations = $variations; | ||
$this->contentService = $contentService; | ||
$this->configMappings = $configMappings; | ||
} | ||
|
||
public function postProcessValueHash($outgoingValueHash) | ||
{ | ||
if (!\is_array($outgoingValueHash)) { | ||
return $outgoingValueHash; | ||
} | ||
|
||
if ($outgoingValueHash['destinationContentId'] === null) { | ||
return $outgoingValueHash; | ||
} | ||
|
||
$imageContent = $this->contentService->loadContent((int) $outgoingValueHash['destinationContentId']); | ||
|
||
$field = $imageContent->getField($this->configMappings['content_field_identifier']); | ||
|
||
$imageId = $imageContent->id . '-' . $field->id . '-' . $imageContent->versionInfo->versionNo; | ||
foreach ($this->variations as $variationIdentifier) { | ||
$outgoingValueHash['variations'][$variationIdentifier] = [ | ||
'href' => $this->router->generate( | ||
'ezpublish_rest_binaryContent_getImageVariation', | ||
[ | ||
'imageId' => $imageId, | ||
'variationIdentifier' => $variationIdentifier, | ||
] | ||
), | ||
]; | ||
} | ||
|
||
return $outgoingValueHash; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.