EntityFormInterface.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace Drupal\Core\Entity;
  3. use Drupal\Core\Extension\ModuleHandlerInterface;
  4. use Drupal\Core\Form\BaseFormIdInterface;
  5. use Drupal\Core\Form\FormStateInterface;
  6. use Drupal\Core\Routing\RouteMatchInterface;
  7. use Drupal\Core\StringTranslation\TranslationInterface;
  8. /**
  9. * Defines an interface for entity form classes.
  10. */
  11. interface EntityFormInterface extends BaseFormIdInterface {
  12. /**
  13. * Sets the operation for this form.
  14. *
  15. * @param string $operation
  16. * The name of the current operation.
  17. *
  18. * @return $this
  19. */
  20. public function setOperation($operation);
  21. /**
  22. * Gets the operation identifying the form.
  23. *
  24. * @return string
  25. * The name of the operation.
  26. */
  27. public function getOperation();
  28. /**
  29. * Gets the form entity.
  30. *
  31. * The form entity which has been used for populating form element defaults.
  32. *
  33. * @return \Drupal\Core\Entity\EntityInterface
  34. * The current form entity.
  35. */
  36. public function getEntity();
  37. /**
  38. * Sets the form entity.
  39. *
  40. * Sets the form entity which will be used for populating form element
  41. * defaults. Usually, the form entity gets updated by
  42. * \Drupal\Core\Entity\EntityFormInterface::submit(), however this may
  43. * be used to completely exchange the form entity, e.g. when preparing the
  44. * rebuild of a multi-step form.
  45. *
  46. * @param \Drupal\Core\Entity\EntityInterface $entity
  47. * The entity the current form should operate upon.
  48. *
  49. * @return $this
  50. */
  51. public function setEntity(EntityInterface $entity);
  52. /**
  53. * Determines which entity will be used by this form from a RouteMatch object.
  54. *
  55. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  56. * The route match.
  57. * @param string $entity_type_id
  58. * The entity type identifier.
  59. *
  60. * @return \Drupal\Core\Entity\EntityInterface
  61. * The entity object as determined from the passed-in route match.
  62. */
  63. public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id);
  64. /**
  65. * Builds an updated entity object based upon the submitted form values.
  66. *
  67. * For building the updated entity object the form's entity is cloned and
  68. * the submitted form values are copied to entity properties. The form's
  69. * entity remains unchanged.
  70. *
  71. * @see \Drupal\Core\Entity\EntityFormInterface::getEntity()
  72. *
  73. * @param array $form
  74. * A nested array form elements comprising the form.
  75. * @param \Drupal\Core\Form\FormStateInterface $form_state
  76. * The current state of the form.
  77. *
  78. * @return \Drupal\Core\Entity\EntityInterface
  79. * An updated copy of the form's entity object.
  80. */
  81. public function buildEntity(array $form, FormStateInterface $form_state);
  82. /**
  83. * Form submission handler for the 'save' action.
  84. *
  85. * Normally this method should be overridden to provide specific messages to
  86. * the user and redirect the form after the entity has been saved.
  87. *
  88. * @param array $form
  89. * An associative array containing the structure of the form.
  90. * @param \Drupal\Core\Form\FormStateInterface $form_state
  91. * The current state of the form.
  92. *
  93. * @return int
  94. * Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
  95. */
  96. public function save(array $form, FormStateInterface $form_state);
  97. /**
  98. * Sets the string translation service for this form.
  99. *
  100. * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
  101. * The translation manager.
  102. *
  103. * @return $this
  104. */
  105. public function setStringTranslation(TranslationInterface $string_translation);
  106. /**
  107. * Sets the module handler for this form.
  108. *
  109. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
  110. * The module handler.
  111. *
  112. * @return $this
  113. */
  114. public function setModuleHandler(ModuleHandlerInterface $module_handler);
  115. /**
  116. * Sets the entity manager for this form.
  117. *
  118. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
  119. * The entity manager.
  120. *
  121. * @return $this
  122. *
  123. * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
  124. *
  125. * @todo Remove this set call in https://www.drupal.org/node/2603542.
  126. */
  127. public function setEntityManager(EntityManagerInterface $entity_manager);
  128. /**
  129. * Sets the entity type manager for this form.
  130. *
  131. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
  132. * The entity type manager.
  133. *
  134. * @return $this
  135. */
  136. public function setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager);
  137. }