|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\Imagine\ImageAsset; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\ContentService; |
|
12
|
|
|
use eZ\Publish\API\Repository\Values\Content\Field; |
|
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\VersionInfo; |
|
14
|
|
|
use eZ\Publish\Core\FieldType\ImageAsset\AssetMapper; |
|
15
|
|
|
use eZ\Publish\SPI\FieldType\Value; |
|
16
|
|
|
use eZ\Publish\SPI\Variation\Values\Variation; |
|
17
|
|
|
use eZ\Publish\SPI\Variation\VariationHandler; |
|
18
|
|
|
use eZ\Publish\Core\FieldType\ImageAsset\Value as ImageAssetValue; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Alias Generator Decorator allowing generate variations based on passed ImageAsset\Value. |
|
22
|
|
|
*/ |
|
23
|
|
|
class AliasGenerator implements VariationHandler |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var \eZ\Publish\SPI\Variation\VariationHandler |
|
27
|
|
|
*/ |
|
28
|
|
|
private $innerAliasGenerator; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \eZ\Publish\API\Repository\ContentService |
|
32
|
|
|
*/ |
|
33
|
|
|
private $contentService; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var \eZ\Publish\Core\FieldType\ImageAsset\AssetMapper |
|
37
|
|
|
*/ |
|
38
|
|
|
private $assetMapper; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param \eZ\Publish\SPI\Variation\VariationHandler $innerAliasGenerator |
|
42
|
|
|
* @param \eZ\Publish\API\Repository\ContentService $contentService |
|
43
|
|
|
* @param \eZ\Publish\Core\FieldType\ImageAsset\AssetMapper $assetMapper |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct( |
|
46
|
|
|
VariationHandler $innerAliasGenerator, |
|
47
|
|
|
ContentService $contentService, |
|
48
|
|
|
AssetMapper $assetMapper) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->innerAliasGenerator = $innerAliasGenerator; |
|
51
|
|
|
$this->contentService = $contentService; |
|
52
|
|
|
$this->assetMapper = $assetMapper; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getVariation(Field $field, VersionInfo $versionInfo, $variationName, array $parameters = []): Variation |
|
59
|
|
|
{ |
|
60
|
|
|
if ($this->supportsValue($field->value)) { |
|
61
|
|
|
$destinationContent = $this->contentService->loadContent( |
|
62
|
|
|
$field->value->destinationContentId |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
return $this->innerAliasGenerator->getVariation( |
|
66
|
|
|
$this->assetMapper->getAssetField($destinationContent), |
|
67
|
|
|
$destinationContent->versionInfo, |
|
68
|
|
|
$variationName, |
|
69
|
|
|
$parameters |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $this->innerAliasGenerator->getVariation($field, $versionInfo, $variationName, $parameters); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Returns TRUE if the value is supported by alias generator. |
|
78
|
|
|
* |
|
79
|
|
|
* @param \eZ\Publish\SPI\FieldType\Value $value |
|
80
|
|
|
* |
|
81
|
|
|
* @return bool |
|
82
|
|
|
*/ |
|
83
|
|
|
public function supportsValue(Value $value): bool |
|
84
|
|
|
{ |
|
85
|
|
|
return $value instanceof ImageAssetValue; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|