Browse Source

Update hook documentation

merge-requests/20/merge
Chi 8 months ago
parent
commit
34ce474c21
  1. 26
      twig_tweak.api.php

26
twig_tweak.api.php

@ -24,19 +24,13 @@ use Twig\TwigTest;
*/
function hook_twig_tweak_functions_alter(array &$functions): void {
// A simple way to implement lazy loaded global variables.
$functions[] = new TwigFunction('var', function (string $name) {
$value = NULL;
switch ($name) {
case 'foo':
$value = 'Foo';
break;
case 'bar':
$value = 'Bar';
break;
}
return $value;
});
$callback = static fn (string $name): ?string =>
match ($name) {
'foo' => 'Foo',
'bar' => 'Bar',
default => NULL,
};
$functions[] = new TwigFunction('var', $callback);
}
/**
@ -58,9 +52,9 @@ function hook_twig_tweak_filters_alter(array &$filters): void {
* Twig tests to alter.
*/
function hook_twig_tweak_tests_alter(array &$tests): void {
$tests[] = new TwigTest('outdated', function (NodeInterface $node): bool {
return \Drupal::time()->getRequestTime() - $node->getCreatedTime() > 3600 * 24 * 365;
});
$callback = static fn (NodeInterface $node): bool =>
\Drupal::time()->getRequestTime() - $node->getCreatedTime() > 3600 * 24 * 365;
$tests[] = new TwigTest('outdated', $callback);
}
/**

Loading…
Cancel
Save