Interim commit.
[yaffs-website] / web / modules / contrib / token / src / TreeBuilderInterface.php
1 <?php
2
3 namespace Drupal\token;
4
5 interface TreeBuilderInterface {
6
7   /**
8    * The maximum depth for token tree recursion.
9    */
10   const MAX_DEPTH = 9;
11
12   /**
13    * Build a tree array of tokens used for themeing or information.
14    *
15    * @param string $token_type
16    *   The token type.
17    * @param array $options
18    *   (optional) An associative array of additional options, with the following
19    *   elements:
20    *   - 'flat' (defaults to FALSE): Set to true to generate a flat list of
21    *     token information. Otherwise, child tokens will be inside the
22    *     'children' parameter of a token.
23    *   - 'restricted' (defaults to FALSE): Set to true to how restricted tokens.
24    *   - 'depth' (defaults to 4): Maximum number of token levels to recurse.
25    *
26    * @return array
27    *   The token information constructed in a tree or flat list form depending
28    *   on $options['flat'].
29    */
30   public function buildTree($token_type, array $options = []);
31
32   /**
33    * Flatten a token tree.
34    *
35    * @param array $tree
36    *   The tree array as returned by TreeBuilderInterface::buildTree().
37    *
38    * @return array
39    *   The flattened version of the tree.
40    */
41   public function flattenTree(array $tree);
42
43   /**
44    * Build a render array with token tree built as per specified options.
45    *
46    * @param array $token_types
47    *   An array containing token types that should be shown in the tree.
48    * @param array $options
49    *   (optional) An associative array to control which tokens are shown and
50    *   how. The properties available are:
51    *   - 'global_types' (defaults to TRUE): Show all global token types along
52    *     with the specified types.
53    *   - 'click_insert' (defaults to TRUE): Include classes and caption to show
54    *     allow inserting tokens in fields by clicking on them.
55    *   - 'show_restricted' (defaults to FALSE): Show restricted tokens in the
56    *     tree.
57    *   - 'show_nested' (defaults to FALSE): If this token is nested and should
58    *     therefor not show on the token browser as a top level token.
59    *   - 'recursion_limit' (defaults to 3): Only show tokens up to the specified
60    *     depth.
61    *
62    * @return array
63    *   Render array for the token tree.
64    */
65   public function buildRenderable(array $token_types, array $options = []);
66
67   /**
68    * Build a render array with token tree containing all possible tokens.
69    *
70    * @param array $options
71    *   (optional) An associative array to control which tokens are shown and
72    *   how. The properties available are: See
73    *   \Drupal\token\TreeBuilderInterface::buildRenderable() for details.
74    *
75    * @return array
76    *   Render array for the token tree.
77    */
78   public function buildAllRenderable(array $options = []);
79 }