Initial Drupal 11 with DDEV setup
This commit is contained in:
9
vendor/chi-teck/drupal-code-generator/templates/Service/_twig-extension/services.twig
vendored
Normal file
9
vendor/chi-teck/drupal-code-generator/templates/Service/_twig-extension/services.twig
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
{% import '@lib/di.twig' as di %}
|
||||
services:
|
||||
{{ machine_name }}.twig_extension:
|
||||
class: Drupal\{{ machine_name }}\{{ class }}
|
||||
{% if services %}
|
||||
arguments: [{{ di.arguments(services) }}]
|
||||
{% endif %}
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
71
vendor/chi-teck/drupal-code-generator/templates/Service/_twig-extension/twig-extension.twig
vendored
Normal file
71
vendor/chi-teck/drupal-code-generator/templates/Service/_twig-extension/twig-extension.twig
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
{% import '@lib/di.twig' as di %}
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\{{ machine_name }};
|
||||
|
||||
{% apply sort_namespaces %}
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
use Twig\TwigTest;
|
||||
{% if services %}
|
||||
{{ di.use(services) }}
|
||||
{% endif %}
|
||||
{% endapply %}
|
||||
|
||||
/**
|
||||
* Twig extension.
|
||||
*/
|
||||
final class {{ class }} extends AbstractExtension {
|
||||
{% if services %}
|
||||
|
||||
/**
|
||||
* Constructs the extension object.
|
||||
*/
|
||||
public function __construct(
|
||||
{{ di.signature(services) }}
|
||||
) {}
|
||||
{% endif %}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFunctions(): array {
|
||||
$functions[] = new TwigFunction(
|
||||
'example',
|
||||
static function (string $argument): string {
|
||||
return 'Example: ' . $argument;
|
||||
},
|
||||
);
|
||||
return $functions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilters(): array {
|
||||
$filters[] = new TwigFilter(
|
||||
'example',
|
||||
static function (string $text): string {
|
||||
return str_replace('example', 'EXAMPLE', $text);
|
||||
},
|
||||
);
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTests(): array {
|
||||
$tests[] = new TwigTest(
|
||||
'example',
|
||||
static function (string $text): bool {
|
||||
return $text === 'example';
|
||||
},
|
||||
);
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user