Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| NameFormatHelpTwigExtension | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| getFunctions | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| getTokenHelp | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Drupal\name\Twig; |
| 6 | |
| 7 | use Drupal\name\Utility\NameFormatHelp; |
| 8 | use Twig\Extension\AbstractExtension; |
| 9 | use Twig\TwigFunction; |
| 10 | |
| 11 | /** |
| 12 | * Twig extension that exposes format-token help to help topic templates. |
| 13 | * |
| 14 | * Registers the name_format_token_help() function, which returns a render |
| 15 | * array for use with render_var() in help topic Twig files. This follows |
| 16 | * the same pattern as Drupal core's help_route_link() / help_topic_link() |
| 17 | * functions provided by \Drupal\help\HelpTwigExtension. |
| 18 | * |
| 19 | * @internal |
| 20 | * Tagged services are internal. |
| 21 | */ |
| 22 | class NameFormatHelpTwigExtension extends AbstractExtension { |
| 23 | |
| 24 | /** |
| 25 | * {@inheritdoc} |
| 26 | */ |
| 27 | public function getFunctions(): array { |
| 28 | return [ |
| 29 | new TwigFunction( |
| 30 | 'name_format_token_help', |
| 31 | [$this, 'getTokenHelp'], |
| 32 | ), |
| 33 | ]; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Returns a render array for the format token reference. |
| 38 | * |
| 39 | * Intended for use in help topic templates via render_var(): |
| 40 | * @code |
| 41 | * {{ render_var(name_format_token_help()) }} |
| 42 | * @endcode |
| 43 | * |
| 44 | * @return array<string, mixed> |
| 45 | * A Drupal render array using the name_format_parameter_help theme. |
| 46 | */ |
| 47 | public function getTokenHelp(): array { |
| 48 | return NameFormatHelp::renderableTokenReference(); |
| 49 | } |
| 50 | |
| 51 | } |