Completed
Push — master ( b7d603...d97993 )
by Paweł
07:44
created

ArticlePreviewTemplateHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A enablePreview() 0 6 1
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\Model\ArticleInterface;
20
use SWP\Component\TemplatesSystem\Gimme\Context\Context;
21
use SWP\Component\TemplatesSystem\Gimme\Factory\MetaFactoryInterface;
22
23
final class ArticlePreviewTemplateHelper implements ArticlePreviewTemplateHelperInterface
24
{
25
    /**
26
     * @var MetaFactoryInterface
27
     */
28
    private $metaFactory;
29
30
    /**
31
     * @var Context
32
     */
33
    private $context;
34
35
    /**
36
     * ArticlePreviewTemplateHelper constructor.
37
     *
38
     * @param MetaFactoryInterface $metaFactory
39
     * @param Context              $context
40
     */
41
    public function __construct(MetaFactoryInterface $metaFactory, Context $context)
42
    {
43
        $this->metaFactory = $metaFactory;
44
        $this->context = $context;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function enablePreview(ArticleInterface $article): void
51
    {
52
        $this->context->setPreviewMode(true);
53
        $this->context->setCurrentPage($this->metaFactory->create($article->getRoute()));
54
        $this->context->getMetaForValue($article);
55
    }
56
}
57