Completed
Push — master ( 9d097e...047422 )
by Gaetano
09:01
created

eZObjectWrapperExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Kaliop\eZObjectWrapperBundle\Twig;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
7
class eZObjectWrapperExtension extends \Twig_Extension
8
{
9
    private $container;
10
11
    /**
12
     * @param ContainerInterface $container
13
     */
14
    public function __construct(ContainerInterface $container)
15
    {
16
        $this->container = $container;
17
    }
18
19
    public function getFunctions()
20
    {
21
        return array(
22
            new \Twig_SimpleFunction('render_location', array($this,'renderLocation'), array('is_safe' => array('html'))),
23
        );
24
    }
25
26
    /**
27
     * Render a location according to the viewType and the ContentType set in override.yml, without doing a sub-request.
28
     * Note: we can NOT inject directly the 'ezpublish.controller.content.view' service because it generates a ServiceCircularReferenceException
29
     *
30
     * @param int $locationID
31
     * @param string $viewType
32
     * @param array $params
33
     * @return string generally it is safe html and does not need to be further encoded/escaped
34
     */
35
    public function renderLocation($locationID, $viewType, $params = array())
36
    {
37
        $rendering = $this->container->get('ezpublish.controller.content.view')
38
            ->viewLocation($locationID, $viewType, false, $params);
39
40
        return $rendering->getContent();
41
    }
42
43
    public function getName()
44
    {
45
        return 'ezobject_wrapper_extension';
46
    }
47
}