1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\NodeSearchBundle\Twig; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
6
|
|
|
use Kunstmaan\NodeBundle\Entity\HasNodeInterface; |
7
|
|
|
use Kunstmaan\NodeBundle\Entity\Node; |
8
|
|
|
use Kunstmaan\NodeSearchBundle\Helper\IndexablePagePartsService; |
9
|
|
|
use Kunstmaan\PagePartBundle\Helper\HasPagePartsInterface; |
10
|
|
|
|
11
|
|
|
class KunstmaanNodeSearchTwigExtension extends \Twig_Extension |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var EntityManager |
15
|
|
|
*/ |
16
|
|
|
private $em; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var IndexablePagePartsService |
20
|
|
|
*/ |
21
|
|
|
private $indexablePagePartsService; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param EntityManager $em |
25
|
|
|
* @param IndexablePagePartsService $indexablePagePartsService |
26
|
|
|
*/ |
27
|
|
|
public function __construct(EntityManager $em, IndexablePagePartsService $indexablePagePartsService) |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$this->em = $em; |
30
|
|
|
$this->indexablePagePartsService = $indexablePagePartsService; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Returns a list of functions to add to the existing list. |
35
|
|
|
* |
36
|
|
|
* @return array An array of functions |
|
|
|
|
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function getFunctions() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
return array( |
41
|
|
|
new \Twig_SimpleFunction('get_parent_page', array($this, 'getParentPage')), |
|
|
|
|
42
|
|
|
new \Twig_SimpleFunction('render_indexable_pageparts', array($this, 'renderIndexablePageParts'), array('needs_environment' => true, 'needs_context' => true, 'is_safe' => array('html'))), |
|
|
|
|
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param HasNodeInterface $page |
48
|
|
|
* @param string $locale |
49
|
|
|
* |
50
|
|
|
* @return HasNodeInterface |
51
|
|
|
*/ |
52
|
|
|
public function getParentPage(HasNodeInterface $page, $locale) |
53
|
|
|
{ |
54
|
|
|
/** @var Node $node */ |
55
|
|
|
$node = $this->em->getRepository('KunstmaanNodeBundle:Node')->getNodeFor($page); |
56
|
|
|
$parentNode = $node->getParent(); |
57
|
|
|
$nodeTranslation = $parentNode->getNodeTranslation($locale); |
58
|
|
|
$parentPage = $nodeTranslation->getRef($this->em); |
59
|
|
|
|
60
|
|
|
return $parentPage; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param \Twig_Environment $env |
65
|
|
|
* @param array $twigContext The twig context |
66
|
|
|
* @param HasPagePartsInterface $page The page |
67
|
|
|
* @param string $contextName The pagepart context |
68
|
|
|
* @param array $parameters Some extra parameters |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
View Code Duplication |
public function renderIndexablePageParts( |
|
|
|
|
73
|
|
|
\Twig_Environment $env, |
74
|
|
|
array $twigContext, |
75
|
|
|
HasPagePartsInterface $page, |
76
|
|
|
$contextName = 'main', |
77
|
|
|
array $parameters = array() |
78
|
|
|
) { |
79
|
|
|
$template = $env->loadTemplate('KunstmaanNodeSearchBundle:PagePart:view.html.twig'); |
80
|
|
|
$pageparts = $this->indexablePagePartsService->getIndexablePageParts($page, $contextName); |
81
|
|
|
$newTwigContext = array_merge( |
82
|
|
|
$parameters, |
83
|
|
|
array( |
84
|
|
|
'pageparts' => $pageparts, |
85
|
|
|
) |
86
|
|
|
); |
87
|
|
|
$newTwigContext = array_merge($newTwigContext, $twigContext); |
88
|
|
|
|
89
|
|
|
return $template->render($newTwigContext); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.