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