EntityFormControllerInterface.php 5.14 KB
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Contains \Drupal\Core\Entity\EntityFormControllerInterface.
6
7
 */

8
namespace Drupal\Core\Entity;
9

10
use Drupal\Core\Extension\ModuleHandlerInterface;
11
use Drupal\Core\Form\BaseFormIdInterface;
12
use Drupal\Core\StringTranslation\TranslationInterface;
13
use Drupal\entity\EntityFormDisplayInterface;
14

15
16
17
/**
 * Defines a common interface for entity form controller classes.
 */
18
interface EntityFormControllerInterface extends BaseFormIdInterface {
19
20
21
22
23
24
25
26
27
28

  /**
   * Returns the code identifying the active form language.
   *
   * @param array $form_state
   *   An associative array containing the current state of the form.
   *
   * @return string
   *   The form language code.
   */
29
  public function getFormLangcode(array &$form_state);
30

31
32
33
34
  /**
   * Checks whether the current form language matches the entity one.
   *
   * @param array $form_state
35
   *   A keyed array containing the current state of the form.
36
37
38
39
   *
   * @return boolean
   *   Returns TRUE if the entity form language matches the entity one.
   */
40
  public function isDefaultFormLangcode(array $form_state);
41

42
43
44
45
46
47
48
49
50
51
52
  /**
   * Sets the operation for this form.
   *
   * @param string $operation
   *   The name of the current operation.
   *
   * @return self
   *   The entity form.
   */
  public function setOperation($operation);

53
54
55
56
57
58
59
60
  /**
   * Returns the operation identifying the form controller.
   *
   * @return string
   *   The name of the operation.
   */
  public function getOperation();

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  /**
   * Returns the form display.
   *
   * @param array $form_state
   *   An associative array containing the current state of the form.
   *
   * @return \Drupal\entity\EntityFormDisplayInterface
   *   The current form display.
   */
  public function getFormDisplay(array $form_state);

  /**
   * Sets the form display.
   *
   * Sets the form display which will be used for populating form element
   * defaults.
   *
   * @param \Drupal\entity\EntityFormDisplayInterface $form_display
   *   The form display that the current form operates with.
   * @param array $form_state
   *   An associative array containing the current state of the form.
   */
  public function setFormDisplay(EntityFormDisplayInterface $form_display, array &$form_state);

85
86
87
88
89
90
91
92
  /**
   * Returns the form entity.
   *
   * The form entity which has been used for populating form element defaults.
   *
   * @param array $form_state
   *   An associative array containing the current state of the form.
   *
93
   * @return \Drupal\Core\Entity\EntityInterface
94
95
   *   The current form entity.
   */
96
  public function getEntity();
97
98
99
100
101
102

  /**
   * Sets the form entity.
   *
   * Sets the form entity which will be used for populating form element
   * defaults. Usually, the form entity gets updated by
103
   * \Drupal\Core\Entity\EntityFormControllerInterface::submit(), however this may
104
105
106
   * be used to completely exchange the form entity, e.g. when preparing the
   * rebuild of a multi-step form.
   *
107
   * @param \Drupal\Core\Entity\EntityInterface $entity
108
109
   *   The entity the current form should operate upon.
   */
110
  public function setEntity(EntityInterface $entity);
111
112
113
114
115
116
117
118

  /**
   * Builds an updated entity object based upon the submitted form values.
   *
   * For building the updated entity object the form's entity is cloned and
   * the submitted form values are copied to entity properties. The form's
   * entity remains unchanged.
   *
119
   * @see \Drupal\Core\Entity\EntityFormControllerInterface::getEntity()
120
121
122
123
124
125
   *
   * @param array $form
   *   A nested array form elements comprising the form.
   * @param array $form_state
   *   An associative array containing the current state of the form.
   *
126
   * @return \Drupal\Core\Entity\EntityInterface
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
   *   An updated copy of the form's entity object.
   */
  public function buildEntity(array $form, array &$form_state);

  /**
   * Validates the submitted form values of the entity form.
   *
   * @param array $form
   *   A nested array form elements comprising the form.
   * @param array $form_state
   *   An associative array containing the current state of the form.
   */
  public function validate(array $form, array &$form_state);

  /**
   * Updates the form's entity by processing this submission's values.
   *
   * Note: Before this can be safely invoked the entity form must have passed
   * validation, i.e. only add this as form #submit handler if validation is
   * added as well.
   *
   * @param array $form
   *   A nested array form elements comprising the form.
   * @param array $form_state
   *   An associative array containing the current state of the form.
   */
  public function submit(array $form, array &$form_state);

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
  /**
   * Sets the translation manager for this form.
   *
   * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager
   *   The translation manager.
   *
   * @return self
   *   The entity form.
   */
  public function setTranslationManager(TranslationInterface $translation_manager);

  /**
   * Sets the module handler for this form.
   *
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   *
   * @return self
   *   The entity form.
   */
  public function setModuleHandler(ModuleHandlerInterface $module_handler);

177
}