OptionsProviderInterface.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Drupal\Core\TypedData;
  3. use Drupal\Core\Session\AccountInterface;
  4. /**
  5. * Interface for retrieving all possible and settable values.
  6. *
  7. * While possible values specify which values existing data might have, settable
  8. * values define the values that are allowed to be set by a user.
  9. *
  10. * For example, in an workflow scenario, the settable values for a state field
  11. * might depend on the currently set state, while possible values are all
  12. * states. Thus settable values would be used in an editing context, while
  13. * possible values would be used for presenting filtering options in a search.
  14. *
  15. * For convenience, lists of both settable and possible values are also provided
  16. * as structured options arrays that can be used in an Options widget such as a
  17. * select box or checkboxes.
  18. *
  19. * Note that this interface is mostly applicable for primitive data values, but
  20. * can be used on complex data structures if a (primitive) main property is
  21. * specified. In that case, the allowed values and options apply to the main
  22. * property only.
  23. *
  24. * @see \Drupal\options\Plugin\Field\FieldWidget\OptionsWidgetBase
  25. */
  26. interface OptionsProviderInterface {
  27. /**
  28. * Returns an array of possible values.
  29. *
  30. * If the optional $account parameter is passed, then the array is filtered to
  31. * values viewable by the account.
  32. *
  33. * @param \Drupal\Core\Session\AccountInterface $account
  34. * (optional) The user account for which to filter the possible values. If
  35. * omitted, all possible values are returned.
  36. *
  37. * @return array
  38. * An array of possible values.
  39. */
  40. public function getPossibleValues(AccountInterface $account = NULL);
  41. /**
  42. * Returns an array of possible values with labels for display.
  43. *
  44. * If the optional $account parameter is passed, then the array is filtered to
  45. * values viewable by the account.
  46. *
  47. * @param \Drupal\Core\Session\AccountInterface $account
  48. * (optional) The user account for which to filter the possible options.
  49. * If omitted, all possible options are returned.
  50. *
  51. * @return array
  52. * An array of possible options for the object that may be used in an
  53. * Options widget, for example when existing data should be filtered. It may
  54. * either be a flat array of option labels keyed by values, or a
  55. * two-dimensional array of option groups (array of flat option arrays,
  56. * keyed by option group label). Note that labels should NOT be sanitized.
  57. */
  58. public function getPossibleOptions(AccountInterface $account = NULL);
  59. /**
  60. * Returns an array of settable values.
  61. *
  62. * If the optional $account parameter is passed, then the array is filtered to
  63. * values settable by the account.
  64. *
  65. * @param \Drupal\Core\Session\AccountInterface $account
  66. * (optional) The user account for which to filter the settable values. If
  67. * omitted, all settable values are returned.
  68. *
  69. * @return array
  70. * An array of settable values.
  71. */
  72. public function getSettableValues(AccountInterface $account = NULL);
  73. /**
  74. * Returns an array of settable values with labels for display.
  75. *
  76. * If the optional $account parameter is passed, then the array is filtered to
  77. * values settable by the account.
  78. *
  79. * @param \Drupal\Core\Session\AccountInterface $account
  80. * (optional) The user account for which to filter the settable options. If
  81. * omitted, all settable options are returned.
  82. *
  83. * @return array
  84. * An array of settable options for the object that may be used in an
  85. * Options widget, usually when new data should be entered. It may either be
  86. * a flat array of option labels keyed by values, or a two-dimensional array
  87. * of option groups (array of flat option arrays, keyed by option group
  88. * label). Note that labels should NOT be sanitized.
  89. */
  90. public function getSettableOptions(AccountInterface $account = NULL);
  91. }