|
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\Service; |
|
18
|
|
|
|
|
19
|
|
|
use SWP\Bundle\ContentBundle\Factory\ArticleFactoryInterface; |
|
20
|
|
|
use SWP\Bundle\ContentBundle\Model\ArticleInterface; |
|
21
|
|
|
use SWP\Bundle\ContentBundle\Model\RouteInterface; |
|
22
|
|
|
use SWP\Bundle\CoreBundle\Model\PackageInterface; |
|
23
|
|
|
use SWP\Bundle\CoreBundle\Processor\ArticleBodyProcessorInterface; |
|
24
|
|
|
use SWP\Component\Common\Exception\NotFoundHttpException; |
|
25
|
|
|
|
|
26
|
|
|
final class ArticlePreviewer implements ArticlePreviewerInterface |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var ArticleBodyProcessorInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $articleBodyProcessor; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var ArticleFactoryInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private $articleFactory; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var ArticlePreviewTemplateHelperInterface |
|
40
|
|
|
*/ |
|
41
|
|
|
private $articlePreviewHelper; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* ArticlePreviewer constructor. |
|
45
|
|
|
* |
|
46
|
|
|
* @param ArticleFactoryInterface $articleFactory |
|
47
|
|
|
* @param ArticleBodyProcessorInterface $articleBodyProcessor |
|
48
|
|
|
* @param ArticlePreviewTemplateHelperInterface $articlePreviewHelper |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct( |
|
51
|
|
|
ArticleFactoryInterface $articleFactory, |
|
52
|
|
|
ArticleBodyProcessorInterface $articleBodyProcessor, |
|
53
|
|
|
ArticlePreviewTemplateHelperInterface $articlePreviewHelper |
|
54
|
|
|
) { |
|
55
|
|
|
$this->articleFactory = $articleFactory; |
|
56
|
|
|
$this->articleBodyProcessor = $articleBodyProcessor; |
|
57
|
|
|
$this->articlePreviewHelper = $articlePreviewHelper; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
public function preview(PackageInterface $package, RouteInterface $route): ArticleInterface |
|
64
|
|
|
{ |
|
65
|
|
|
$article = $this->articleFactory->createFromPackage($package); |
|
66
|
|
|
$this->articleBodyProcessor->fillArticleMedia($package, $article); |
|
67
|
|
|
$article->setRoute($route); |
|
68
|
|
|
|
|
69
|
|
|
if (null === $article->getRoute()) { |
|
70
|
|
|
throw new NotFoundHttpException('There is no route set!'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$this->articlePreviewHelper->enablePreview($article); |
|
74
|
|
|
|
|
75
|
|
|
return $article; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|