1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher Facebook Instant Articles Bundle. |
7
|
|
|
* |
8
|
|
|
* Copyright 2016 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 2016 Sourcefabric z.ú |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace SWP\Bundle\FacebookInstantArticlesBundle\Controller; |
18
|
|
|
|
19
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
20
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
21
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
22
|
|
|
use SWP\Bundle\ContentListBundle\Event\ContentListEvent; |
23
|
|
|
use SWP\Bundle\CoreBundle\Model\ContentListItem; |
24
|
|
|
use SWP\Bundle\FacebookInstantArticlesBundle\Parser\TemplateParser; |
25
|
|
|
use SWP\Component\ContentList\ContentListEvents; |
26
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
27
|
|
|
|
28
|
|
|
class ParsingPreviewController extends Controller |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @Route("/facebook/instantarticles/preview/{articleId}", options={"expose"=true}, name="swp_fbia_preview_parsing") |
32
|
|
|
* @Method("GET") |
33
|
|
|
* @Template() |
34
|
|
|
*/ |
35
|
|
|
public function previewAction($articleId) |
36
|
|
|
{ |
37
|
|
|
/** @var TemplateParser $templateParser */ |
38
|
|
|
$templateParser = $this->get('swp_facebook.template_parser'); |
39
|
|
|
$article = $this->get('swp.provider.article')->getOneById($articleId); |
40
|
|
|
$this->get('swp_template_engine_context.factory.meta_factory')->create($article); |
41
|
|
|
$instantArticle = $templateParser->parse(); |
42
|
|
|
|
43
|
|
|
$contentList = $this->get('swp.repository.content_list')->findOneById(1); |
44
|
|
|
$contentListItem = new ContentListItem(); |
45
|
|
|
$contentListItem->setContent($article); |
46
|
|
|
$contentListItem->setContentList($contentList); |
47
|
|
|
$this->get('event_dispatcher')->dispatch(ContentListEvents::POST_ITEM_ADD, new ContentListEvent( |
48
|
|
|
$contentList, |
49
|
|
|
$contentListItem |
50
|
|
|
)); |
51
|
|
|
|
52
|
|
|
return $this->render('SWPFacebookInstantArticlesBundle:ParsingPreview:preview.html.twig', [ |
53
|
|
|
'instantArticle' => $instantArticle, |
54
|
|
|
'warnings' => $templateParser->getTransformer()->getWarnings(), |
55
|
|
|
]); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|