DomainElementManagerInterface.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace Drupal\domain;
  3. use Drupal\Core\Entity\EntityInterface;
  4. use Drupal\Core\Form\FormStateInterface;
  5. /**
  6. * Handles hidden field options for domain entity references.
  7. *
  8. * Since domain options are restricted for various forms (users, nodes, source)
  9. * we have a base class for handling common use cases. The details of each
  10. * implementation are generally handled by a subclass and invoked within a
  11. * hook_form_alter().
  12. *
  13. * The default implementation, DomainElementManger, works with standard
  14. * multi-value domain entity reference fields.
  15. */
  16. interface DomainElementManagerInterface {
  17. /**
  18. * Resets form options and stores hidden values that the user cannot change.
  19. *
  20. * @param array $form
  21. * The form array.
  22. * @param \Drupal\Core\Form\FormStateInterface $form_state
  23. * The form state object.
  24. * @param string $field_name
  25. * The name of the field to check.
  26. * @param bool $hide_on_disallow
  27. * If the field is set to a value that cannot be altered by the user who
  28. * is not assigned to that domain, pass TRUE to remove the form element
  29. * entirely. See DomainSourceElementManager for the use-case.
  30. *
  31. * @return array
  32. * Return the modified form array.
  33. */
  34. public function setFormOptions(array $form, FormStateInterface $form_state, $field_name, $hide_on_disallow = FALSE);
  35. /**
  36. * Submit function for handling hidden values from a form.
  37. *
  38. * On form submit, loop through the hidden form values and add those to the
  39. * entity being saved.
  40. *
  41. * No return value. Hidden values are added to the field values directly.
  42. *
  43. * @param array $form
  44. * The form array.
  45. * @param \Drupal\Core\Form\FormStateInterface $form_state
  46. * The form state object.
  47. */
  48. public static function submitEntityForm(array &$form, FormStateInterface $form_state);
  49. /**
  50. * Finds options not accessible to the current user.
  51. *
  52. * @param \Drupal\Core\Form\FormStateInterface $form_state
  53. * The form state object.
  54. * @param array $field
  55. * The field element being processed.
  56. */
  57. public function disallowedOptions(FormStateInterface $form_state, array $field);
  58. /**
  59. * Stores a static list of fields that have been disallowed.
  60. *
  61. * @param string $field_name
  62. * The name of the field being processed. Inherited from setFormOptions.
  63. *
  64. * @return array
  65. * An array of field names.
  66. */
  67. public function fieldList($field_name);
  68. /**
  69. * Gets the domain entity reference field values from an entity.
  70. *
  71. * @param \Drupal\Core\Entity\EntityInterface $entity
  72. * The entity to retrieve field data from.
  73. * @param string $field_name
  74. * The name of the field that holds our data.
  75. *
  76. * @return array
  77. * The domain access field values, keyed by id (machine_name) with value of
  78. * the numeric domain_id used by node access.
  79. */
  80. public function getFieldValues(EntityInterface $entity, $field_name);
  81. /**
  82. * Returns the default submit handler to be used for a field element.
  83. *
  84. * @return string
  85. * A fully-qualified class and method name, such as
  86. * '\\Drupal\\domain\\DomainElementManager::submitEntityForm'
  87. *
  88. * The method must be public and static, since it will be called from the
  89. * form submit handler without knowledge of the parent class.
  90. *
  91. * The base implementation is submitEntityForm, and can be overridden by
  92. * specific subclasses.
  93. */
  94. public function getSubmitHandler();
  95. }