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
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/service/twig-extension.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/service/twig-extension.twig
new file mode 100644 (file)
index 0000000..39f9902
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+
+namespace Drupal\{{ machine_name }};
+
+/**
+ * Twig extension.
+ */
+class {{ class }} extends \Twig_Extension {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getName() {
+    return '{{ machine_name }}';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFunctions() {
+    return [
+      new \Twig_SimpleFunction('foo', function ($argument = NULL) {
+        return 'Foo: ' . $argument;
+      }),
+    ];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFilters() {
+    return [
+      new \Twig_SimpleFilter('bar', function ($text) {
+        return str_replace('bar', 'BAR', $text);
+      }),
+    ];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getTests() {
+    return [
+      new \Twig_SimpleTest('color', function ($text) {
+        return preg_match('/^#(?:[0-9a-f]{3}){1,2}$/i', $text);
+      }),
+    ];
+  }
+
+}