1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher Core Bundle. |
7
|
|
|
* |
8
|
|
|
* Copyright 2018 Sourcefabric z.ú. and contributors. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please see the |
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* @copyright 2018 Sourcefabric z.ú |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace SWP\Bundle\CoreBundle\Provider; |
18
|
|
|
|
19
|
|
|
use SWP\Bundle\ContentBundle\Factory\FileFactoryInterface; |
20
|
|
|
use SWP\Bundle\ContentBundle\Model\FileInterface; |
21
|
|
|
use SWP\Bundle\ContentBundle\Model\ImageInterface; |
22
|
|
|
use SWP\Bundle\ContentBundle\Provider\ORM\ArticleMediaAssetProviderInterface; |
23
|
|
|
use SWP\Bundle\CoreBundle\Context\ArticlePreviewContextInterface; |
24
|
|
|
use SWP\Component\Bridge\Model\RenditionInterface; |
25
|
|
|
use SWP\Component\Storage\Factory\FactoryInterface; |
26
|
|
|
|
27
|
|
|
class ArticleMediaAssetProvider implements ArticleMediaAssetProviderInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var ArticleMediaAssetProviderInterface |
31
|
|
|
*/ |
32
|
|
|
private $decoratedArticleMediaAssetProvider; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var ArticlePreviewContextInterface |
36
|
|
|
*/ |
37
|
|
|
private $articlePreviewContext; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var FileFactoryInterface |
41
|
|
|
*/ |
42
|
|
|
private $fileFactory; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var FactoryInterface |
46
|
|
|
*/ |
47
|
|
|
private $imageFactory; |
48
|
|
|
|
49
|
|
|
public function __construct( |
50
|
|
|
ArticleMediaAssetProviderInterface $decoratedArticleMediaAssetProvider, |
51
|
|
|
ArticlePreviewContextInterface $articlePreviewContext, |
52
|
|
|
FileFactoryInterface $fileFactory, |
53
|
|
|
FactoryInterface $imageFactory |
54
|
|
|
) { |
55
|
|
|
$this->decoratedArticleMediaAssetProvider = $decoratedArticleMediaAssetProvider; |
56
|
|
|
$this->articlePreviewContext = $articlePreviewContext; |
57
|
|
|
$this->fileFactory = $fileFactory; |
58
|
|
|
$this->imageFactory = $imageFactory; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getImage(RenditionInterface $rendition): ?ImageInterface |
62
|
|
|
{ |
63
|
|
|
if ($this->articlePreviewContext->isPreview()) { |
64
|
|
|
$image = $this->imageFactory->create(); |
65
|
|
|
$image->setAssetId($rendition->getMedia()); |
66
|
|
|
|
67
|
|
|
return $image; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $this->decoratedArticleMediaAssetProvider->getImage($rendition); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getFile(RenditionInterface $rendition): ?FileInterface |
74
|
|
|
{ |
75
|
|
|
if ($this->articlePreviewContext->isPreview()) { |
76
|
|
|
$file = $this->fileFactory->createFile(); |
77
|
|
|
$file->setAssetId($rendition->getMedia()); |
78
|
|
|
$file->setPreviewUrl($rendition->getHref()); |
79
|
|
|
|
80
|
|
|
return $file; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $this->decoratedArticleMediaAssetProvider->getFile($rendition); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|