This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
drupalcampbristol/vendor/chi-teck/drupal-code-generator/templates/d8/service/twig-extension.twig
2018-11-23 12:29:20 +00:00

67 lines
1.1 KiB
Twig

<?php
namespace Drupal\{{ machine_name }};
{% if di %}
use Drupal\example\ExampleInterface;
{% endif %}
/**
* Twig extension.
*/
class {{ class }} extends \Twig_Extension {
{% if di %}
/**
* The example service.
*
* @var \Drupal\example\ExampleInterface
*/
protected $example;
/**
* Constructs a new {{ class }} instance.
*
* @param \Drupal\example\ExampleInterface $example
* The example service.
*/
public function __construct(ExampleInterface $example) {
$this->example = $example;
}
{% endif %}
/**
* {@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);
}),
];
}
}