EntityFormBuilderInterface.php 2.17 KB
Newer Older
1 2 3 4 5 6
<?php

namespace Drupal\Core\Entity;

/**
 * Builds entity forms.
7 8 9 10
 *
 * This is like \Drupal\Core\Form\FormBuilderInterface but instead of looking
 * up the form class by class name, it looks up the form class based on the
 * entity type and operation.
11 12 13 14
 */
interface EntityFormBuilderInterface {

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

}