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