Completed
Push — 1.4 ( 6a61c0...59673b )
by Paweł
15s
created

EmbeddedImageProcessor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Core Bundle.
5
 *
6
 * Copyright 2019 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2019 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\CoreBundle\Processor;
16
17
use SWP\Bundle\ContentBundle\File\FileExtensionCheckerInterface;
18
use SWP\Bundle\ContentBundle\Manager\MediaManagerInterface;
19
use SWP\Bundle\ContentBundle\Model\ImageRendition;
20
use SWP\Bundle\ContentBundle\Processor\EmbeddedImageProcessor as BaseEmbeddedImageProcessor;
21
use SWP\Bundle\CoreBundle\Context\ArticlePreviewContextInterface;
22
23
final class EmbeddedImageProcessor extends BaseEmbeddedImageProcessor
24
{
25
    /**
26
     * @var ArticlePreviewContextInterface
27
     */
28
    private $articlePreviewContext;
29
30
    public function __construct(
31
        MediaManagerInterface $mediaManager,
32
        FileExtensionCheckerInterface $fileExtensionChecker,
33
        ArticlePreviewContextInterface $articlePreviewContext
34
    ) {
35
        parent::__construct($mediaManager, $fileExtensionChecker);
36
        $this->articlePreviewContext = $articlePreviewContext;
37
    }
38
39
    protected function processImageElement(\DOMElement $imageElement, ImageRendition $rendition, string $mediaId)
40
    {
41
        parent::processImageElement($imageElement, $rendition, $mediaId);
42
43
        if ($this->articlePreviewContext->isPreview()) {
44
            $imageElement->setAttribute('src', $rendition->getPreviewUrl());
45
        }
46
    }
47
}
48