3 namespace Drupal\Core\Entity;
5 use Drupal\Core\Extension\ModuleHandlerInterface;
6 use Drupal\Core\Form\BaseFormIdInterface;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\Core\Routing\RouteMatchInterface;
9 use Drupal\Core\StringTranslation\TranslationInterface;
12 * Defines an interface for entity form classes.
14 interface EntityFormInterface extends BaseFormIdInterface {
17 * Sets the operation for this form.
19 * @param string $operation
20 * The name of the current operation.
24 public function setOperation($operation);
27 * Gets the operation identifying the form.
30 * The name of the operation.
32 public function getOperation();
35 * Gets the form entity.
37 * The form entity which has been used for populating form element defaults.
39 * @return \Drupal\Core\Entity\EntityInterface
40 * The current form entity.
42 public function getEntity();
45 * Sets the form entity.
47 * Sets the form entity which will be used for populating form element
48 * defaults. Usually, the form entity gets updated by
49 * \Drupal\Core\Entity\EntityFormInterface::submit(), however this may
50 * be used to completely exchange the form entity, e.g. when preparing the
51 * rebuild of a multi-step form.
53 * @param \Drupal\Core\Entity\EntityInterface $entity
54 * The entity the current form should operate upon.
58 public function setEntity(EntityInterface $entity);
61 * Determines which entity will be used by this form from a RouteMatch object.
63 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
65 * @param string $entity_type_id
66 * The entity type identifier.
68 * @return \Drupal\Core\Entity\EntityInterface
69 * The entity object as determined from the passed-in route match.
71 public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id);
74 * Builds an updated entity object based upon the submitted form values.
76 * For building the updated entity object the form's entity is cloned and
77 * the submitted form values are copied to entity properties. The form's
78 * entity remains unchanged.
80 * @see \Drupal\Core\Entity\EntityFormInterface::getEntity()
83 * A nested array form elements comprising the form.
84 * @param \Drupal\Core\Form\FormStateInterface $form_state
85 * The current state of the form.
87 * @return \Drupal\Core\Entity\EntityInterface
88 * An updated copy of the form's entity object.
90 public function buildEntity(array $form, FormStateInterface $form_state);
93 * Form submission handler for the 'save' action.
95 * Normally this method should be overridden to provide specific messages to
96 * the user and redirect the form after the entity has been saved.
99 * An associative array containing the structure of the form.
100 * @param \Drupal\Core\Form\FormStateInterface $form_state
101 * The current state of the form.
104 * Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
106 public function save(array $form, FormStateInterface $form_state);
109 * Sets the string translation service for this form.
111 * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
112 * The translation manager.
116 public function setStringTranslation(TranslationInterface $string_translation);
119 * Sets the module handler for this form.
121 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
122 * The module handler.
126 public function setModuleHandler(ModuleHandlerInterface $module_handler);
129 * Sets the entity manager for this form.
131 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
132 * The entity manager.
136 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
138 * @todo Remove this set call in https://www.drupal.org/node/2603542.
140 public function setEntityManager(EntityManagerInterface $entity_manager);
143 * Sets the entity type manager for this form.
145 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
146 * The entity type manager.
150 public function setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager);