TokenInterface.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Drupal\token;
  3. interface TokenInterface {
  4. /**
  5. * Returns metadata describing supported token types.
  6. *
  7. * @param $token_type
  8. * The token type for which the metadata is required.
  9. *
  10. * @return array[]
  11. * An array of token type information from hook_token_info() for the
  12. * specified token type.
  13. *
  14. * @see hook_token_info()
  15. * @see hook_token_info_alter()
  16. */
  17. public function getTypeInfo($token_type);
  18. /**
  19. * Returns metadata describing supported a token.
  20. *
  21. * @param $token_type
  22. * The token type for which the metadata is required.
  23. * @param $token
  24. * The token name for which the metadata is required.
  25. *
  26. * @return array[]
  27. * An array of information from hook_token_info() for the specified token.
  28. *
  29. * @see hook_token_info()
  30. * @see hook_token_info_alter()
  31. *
  32. * @deprecated
  33. */
  34. public function getTokenInfo($token_type, $token);
  35. /**
  36. * Get a list of token types that can be used without any context (global).
  37. *
  38. * @return array[]
  39. * An array of global token types.
  40. */
  41. public function getGlobalTokenTypes();
  42. /**
  43. * Validate an array of tokens based on their token type.
  44. *
  45. * @param string $type
  46. * The type of tokens to validate (e.g. 'node', etc.)
  47. * @param string[] $tokens
  48. * A keyed array of tokens, and their original raw form in the source text.
  49. *
  50. * @return string[]
  51. * An array with the invalid tokens in their original raw forms.
  52. */
  53. function getInvalidTokens($type, $tokens);
  54. /**
  55. * Validate tokens in raw text based on possible contexts.
  56. *
  57. * @param string|string[] $value
  58. * A string with the raw text containing the raw tokens, or an array of
  59. * tokens from token_scan().
  60. * @param string[] $valid_types
  61. * An array of token types that will be used when token replacement is
  62. * performed.
  63. *
  64. * @return string[]
  65. * An array with the invalid tokens in their original raw forms.
  66. */
  67. public function getInvalidTokensByContext($value, array $valid_types = []);
  68. }