view vendor/chi-teck/drupal-code-generator/templates/d8/service/twig-extension.twig @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
line wrap: on
line source
{% import 'lib/di.twig' as di %}
<?php

namespace Drupal\{{ machine_name }};

{% if services %}
{{ di.use(services) }}
{% endif %}
/**
 * Twig extension.
 */
class {{ class }} extends \Twig_Extension {

{% if services %}
{{ di.properties(services) }}

  /**
   * Constructs a new {{ class }} object.
   *
{{ di.annotation(services) }}
   */
  public function __construct({{ di.signature(services) }}) {
{{ di.assignment(services) }}
  }

{% 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);
      }),
    ];
  }

}