Pull merge.
[yaffs-website] / web / core / lib / Drupal / Core / Entity / EntityFormInterface.php
1 <?php
2
3 namespace Drupal\Core\Entity;
4
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;
10
11 /**
12  * Defines an interface for entity form classes.
13  */
14 interface EntityFormInterface extends BaseFormIdInterface {
15
16   /**
17    * Sets the operation for this form.
18    *
19    * @param string $operation
20    *   The name of the current operation.
21    *
22    * @return $this
23    */
24   public function setOperation($operation);
25
26   /**
27    * Gets the operation identifying the form.
28    *
29    * @return string
30    *   The name of the operation.
31    */
32   public function getOperation();
33
34   /**
35    * Gets the form entity.
36    *
37    * The form entity which has been used for populating form element defaults.
38    *
39    * @return \Drupal\Core\Entity\EntityInterface
40    *   The current form entity.
41    */
42   public function getEntity();
43
44   /**
45    * Sets the form entity.
46    *
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.
52    *
53    * @param \Drupal\Core\Entity\EntityInterface $entity
54    *   The entity the current form should operate upon.
55    *
56    * @return $this
57    */
58   public function setEntity(EntityInterface $entity);
59
60   /**
61    * Determines which entity will be used by this form from a RouteMatch object.
62    *
63    * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
64    *   The route match.
65    * @param string $entity_type_id
66    *   The entity type identifier.
67    *
68    * @return \Drupal\Core\Entity\EntityInterface
69    *   The entity object as determined from the passed-in route match.
70    */
71   public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id);
72
73   /**
74    * Builds an updated entity object based upon the submitted form values.
75    *
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.
79    *
80    * @see \Drupal\Core\Entity\EntityFormInterface::getEntity()
81    *
82    * @param array $form
83    *   A nested array form elements comprising the form.
84    * @param \Drupal\Core\Form\FormStateInterface $form_state
85    *   The current state of the form.
86    *
87    * @return \Drupal\Core\Entity\EntityInterface
88    *   An updated copy of the form's entity object.
89    */
90   public function buildEntity(array $form, FormStateInterface $form_state);
91
92   /**
93    * Form submission handler for the 'save' action.
94    *
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.
97    *
98    * @param array $form
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.
102    *
103    * @return int
104    *   Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
105    */
106   public function save(array $form, FormStateInterface $form_state);
107
108   /**
109    * Sets the string translation service for this form.
110    *
111    * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
112    *   The translation manager.
113    *
114    * @return $this
115    */
116   public function setStringTranslation(TranslationInterface $string_translation);
117
118   /**
119    * Sets the module handler for this form.
120    *
121    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
122    *   The module handler.
123    *
124    * @return $this
125    */
126   public function setModuleHandler(ModuleHandlerInterface $module_handler);
127
128   /**
129    * Sets the entity manager for this form.
130    *
131    * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
132    *   The entity manager.
133    *
134    * @return $this
135    *
136    * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
137    *
138    * @todo Remove this set call in https://www.drupal.org/node/2603542.
139    */
140   public function setEntityManager(EntityManagerInterface $entity_manager);
141
142   /**
143    * Sets the entity type manager for this form.
144    *
145    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
146    *   The entity type manager.
147    *
148    * @return $this
149    */
150   public function setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager);
151
152 }