EntityFormBuilderInterface.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Drupal\Core\Entity;
  3. /**
  4. * Builds entity forms.
  5. *
  6. * This is like \Drupal\Core\Form\FormBuilderInterface but instead of looking
  7. * up the form class by class name, it looks up the form class based on the
  8. * entity type and operation.
  9. */
  10. interface EntityFormBuilderInterface {
  11. /**
  12. * Gets the built and processed entity form for the given entity.
  13. *
  14. * The form may also be retrieved from the cache if the form was built in a
  15. * previous page load. The form is then passed on for processing, validation,
  16. * and submission if there is proper input.
  17. *
  18. * @param \Drupal\Core\Entity\EntityInterface $entity
  19. * The entity to be created or edited.
  20. * @param string $operation
  21. * (optional) The operation identifying the form variation to be returned.
  22. * Defaults to 'default'. This is typically used in routing:
  23. * @code
  24. * _entity_form: node.book_outline
  25. * @endcode
  26. * where "book_outline" is the value of $operation. The class name for the
  27. * form for each operation (edit, delete, etc.) can be found in the form
  28. * section of the handlers entity annotation. For example:
  29. * @code
  30. * handlers = {
  31. * "form" = {
  32. * "delete" = "Drupal\node\Form\NodeDeleteForm",
  33. * @endcode
  34. * Alternatively, the form class can be set from hook_entity_type_build().
  35. * @param array $form_state_additions
  36. * (optional) An associative array used to build the current state of the
  37. * form. Use this to pass additional information to the form, such as the
  38. * langcode. Defaults to an empty array.
  39. *
  40. * @code
  41. * $form_state_additions['langcode'] = $langcode;
  42. * $form = \Drupal::service('entity.form_builder')->getForm($entity, 'default', $form_state_additions);
  43. * @endcode
  44. *
  45. * @return array
  46. * The processed form for the given entity and operation.
  47. *
  48. * @see \Drupal\Core\Form\FormBuilderInterface::getForm()
  49. * @see \Drupal\Core\Entity\EntityTypeInterface::getFormClass()
  50. * @see \Drupal\Core\Entity\EntityTypeInterface::setFormClass()
  51. * @see system_entity_type_build()
  52. */
  53. public function getForm(EntityInterface $entity, $operation = 'default', array $form_state_additions = []);
  54. }