Completed
Push — 1.0 ( 99ef79...ba8fdc )
by David
01:55
created

TwigExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
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
        $this->entityWrapper = $entityWrapper;
19
    }
20
21
  /**
22
   * {@inheritdoc}
23
   */
24
  public function getFunctions() {
25
      return [
26
          new \Twig_SimpleFunction('easy_entity', [$this, 'easyEntity']),
27
      ];
28
  }
29
30
  /**
31
   * {@inheritdoc}
32
   *
33
   * @deprecated
34
   */
35
  public function getName() {
36
      return 'easy_entity_reader';
37
  }
38
39
    /**
40
     * Wraps an entity object in a "easy" wrapper.
41
     *
42
     * @param EntityInterface $entity
43
     * @return EasyEntityAdapter
44
     */
45
  public function easyEntity(EntityInterface $entity) {
46
      return $this->entityWrapper->wrap($entity);
47
  }
48
}
49