Completed
Push — master ( 6e6249...28ec7c )
by Benjamin
23:40 queued 02:04
created

CMSExtension::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Alpixel\Bundle\CMSBundle\Twig\Extension;
4
5
use Alpixel\Bundle\CMSBundle\Entity\NodeInterface;
6
use Alpixel\Bundle\CMSBundle\Helper\CMSHelper;
7
use Doctrine\Bundle\DoctrineBundle\Registry;
8
9
class CMSExtension extends \Twig_Extension
10
{
11
    protected $contentTypes;
12
    protected $container;
13
    protected $cmsHelper;
14
15
    public function __construct(CMSHelper $cmsHelper, $container, $contentTypes)
16
    {
17
        $this->cmsHelper = $cmsHelper;
18
        $this->container = $container;
19
        $this->contentTypes = $contentTypes;
20
    }
21
22
    public function getName()
23
    {
24
        return 'cms';
25
    }
26
27
    public function getGlobals()
28
    {
29
        return [
30
            'cms_contentTypes' => $this->contentTypes,
31
            'cms_languages'    => $this->container->getParameter('lunetics_locale.allowed_locales'),
32
        ];
33
    }
34
35
    public function getFunctions()
36
    {
37
        return [
38
            new \Twig_SimpleFunction('cms_get_translation', array($this, 'cmsHasTranslation')),
39
        ];
40
    }
41
42
43
    public function getFilters()
44
    {
45
        return [
46
            new \Twig_SimpleFilter('iso_to_country_name', array($this, 'isoToCountryName'))
47
        ];
48
    }
49
50
    public function isoToCountryName($iso)
51
    {
52
        return \Locale::getDisplayLanguage($iso, $this->container->getParameter('locale'));
53
    }
54
55
    public function cmsHasTranslation(NodeInterface $node, $locale)
56
    {
57
        return $this->cmsHelper->nodeGetTranslation($node, $locale);
58
    }
59
60
}
61