X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Ftoken%2Fsrc%2FController%2FTokenTreeController.php;fp=web%2Fmodules%2Fcontrib%2Ftoken%2Fsrc%2FController%2FTokenTreeController.php;h=f233ab2340941386bc824e2e95b951f5e0331e4f;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/token/src/Controller/TokenTreeController.php b/web/modules/contrib/token/src/Controller/TokenTreeController.php new file mode 100644 index 000000000..f233ab234 --- /dev/null +++ b/web/modules/contrib/token/src/Controller/TokenTreeController.php @@ -0,0 +1,56 @@ +treeBuilder = $tree_builder; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('token.tree_builder') + ); + } + + /** + * Page callback to output a token tree as an empty page. + */ + function outputTree(Request $request) { + $options = $request->query->has('options') ? Json::decode($request->query->get('options')) : []; + + // The option token_types may only be an array OR 'all'. If it is not set, + // we assume that only global token types are requested. + $token_types = !empty($options['token_types']) ? $options['token_types'] : []; + if ($token_types == 'all') { + $build = $this->treeBuilder->buildAllRenderable($options); + } + else { + $build = $this->treeBuilder->buildRenderable($token_types, $options); + } + + $build['#cache']['contexts'][] = 'url.query_args:options'; + $build['#title'] = $this->t('Available tokens'); + + return $build; + } + +}