99f5acd9016ea2617ca3dd7506b37506e487936e
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / service / twig-extension.twig
1 <?php
2
3 namespace Drupal\{{ machine_name }};
4
5 {% if di %}
6 use Drupal\example\ExampleInterface;
7
8 {% endif %}
9 /**
10  * Twig extension.
11  */
12 class {{ class }} extends \Twig_Extension {
13
14 {% if di %}
15   /**
16    * The example service.
17    *
18    * @var \Drupal\example\ExampleInterface
19    */
20   protected $example;
21
22   /**
23    * Constructs a new {{ class }} instance.
24    *
25    * @param \Drupal\example\ExampleInterface $example
26    *   The example service.
27    */
28   public function __construct(ExampleInterface $example) {
29     $this->example = $example;
30   }
31
32 {% endif %}
33   /**
34    * {@inheritdoc}
35    */
36   public function getFunctions() {
37     return [
38       new \Twig_SimpleFunction('foo', function ($argument = NULL) {
39         return 'Foo: ' . $argument;
40       }),
41     ];
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function getFilters() {
48     return [
49       new \Twig_SimpleFilter('bar', function ($text) {
50         return str_replace('bar', 'BAR', $text);
51       }),
52     ];
53   }
54
55   /**
56    * {@inheritdoc}
57    */
58   public function getTests() {
59     return [
60       new \Twig_SimpleTest('color', function ($text) {
61         return preg_match('/^#(?:[0-9a-f]{3}){1,2}$/i', $text);
62       }),
63     ];
64   }
65
66 }