From 34ce474c21d5974d295472cc520dd87aa209968c Mon Sep 17 00:00:00 2001 From: Chi Date: Sun, 28 Jan 2024 07:06:38 +0000 Subject: [PATCH] Update hook documentation --- twig_tweak.api.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/twig_tweak.api.php b/twig_tweak.api.php index 0965818..a920c3d 100644 --- a/twig_tweak.api.php +++ b/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); } /**