TwigExtension::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Drupal\easy_entity_reader;
4
5
use Drupal\Core\Entity\EntityInterface;
6
7
/**
8
 * Twig extension with some useful functions and filters.
9
 */
10
class TwigExtension extends \Twig_Extension
11
{
12
    /**
13
     * @var EntityWrapper
14
     */
15
    private $entityWrapper;
16
17
    public function __construct(EntityWrapper $entityWrapper)
18
    {
19
        $this->entityWrapper = $entityWrapper;
20
    }
21
22
  /**
23
   * {@inheritdoc}
24
   */
25
  public function getFunctions()
26
  {
27
      return [
28
          new \Twig_SimpleFunction('easy_entity', [$this, 'easyEntity']),
29
      ];
30
  }
31
32
  /**
33
   * {@inheritdoc}
34
   *
35
   * @deprecated
36
   */
37
  public function getName()
38
  {
39
      return 'easy_entity_reader';
40
  }
41
42
  /**
43
   * Wraps an entity object in a "easy" wrapper.
44
   *
45
   * @param EntityInterface $entity
46
   *
47
   * @return EasyEntityAdapter
48
   */
49
  public function easyEntity(EntityInterface $entity = null)
50
  {
51
      return $entity ? $this->entityWrapper->wrap($entity) : null;
52
  }
53
}
54