Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / service / twig-extension.twig
1 <?php
2
3 namespace Drupal\{{ machine_name }};
4
5 /**
6  * Twig extension.
7  */
8 class {{ class }} extends \Twig_Extension {
9
10   /**
11    * {@inheritdoc}
12    */
13   public function getName() {
14     return '{{ machine_name }}';
15   }
16
17   /**
18    * {@inheritdoc}
19    */
20   public function getFunctions() {
21     return [
22       new \Twig_SimpleFunction('foo', function ($argument = NULL) {
23         return 'Foo: ' . $argument;
24       }),
25     ];
26   }
27
28   /**
29    * {@inheritdoc}
30    */
31   public function getFilters() {
32     return [
33       new \Twig_SimpleFilter('bar', function ($text) {
34         return str_replace('bar', 'BAR', $text);
35       }),
36     ];
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function getTests() {
43     return [
44       new \Twig_SimpleTest('color', function ($text) {
45         return preg_match('/^#(?:[0-9a-f]{3}){1,2}$/i', $text);
46       }),
47     ];
48   }
49
50 }