Completed
Push — master ( 9e1211...19df0f )
by Benjamin
02:32
created

CMSExtension::getFilters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
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\Node;
6
use Alpixel\Bundle\CMSBundle\Helper\CMSHelper;
7
8
class CMSExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
9
{
10
    protected $contentTypes;
11
    protected $container;
12
    protected $cmsHelper;
13
14
    public function __construct(CMSHelper $cmsHelper, $container, $contentTypes = null)
15
    {
16
        $this->cmsHelper = $cmsHelper;
17
        $this->container = $container;
18
        $this->contentTypes = $contentTypes;
19
    }
20
21
    public function getName()
22
    {
23
        return 'cms';
24
    }
25
26
    public function getGlobals()
27
    {
28
        return [
29
            'cms_contentTypes' => $this->contentTypes,
30
        ];
31
    }
32
33
    public function getFunctions()
34
    {
35
        return [
36
            new \Twig_SimpleFunction('cms_contentType_get_description', [$this, 'cmsGetDescription']),
37
        ];
38
    }
39
40
    public function cmsGetDescription(Node $node)
41
    {
42
        $contentType = $this->cmsHelper->getContentTypeFromNodeElementClass($node);
43
        if ($contentType !== null) {
44
            return $contentType['description'];
45
        }
46
    }
47
    
48
}
49