TreeBuilderInterface.php 2.7 KB

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