EntityFormInterface.php 4.35 KB
Newer Older
1 2 3 4
<?php

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

8
namespace Drupal\Core\Entity;
9

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

15
/**
16
 * Defines a common interface for entity form classes.
17
 */
18
interface EntityFormInterface extends BaseFormIdInterface {
19 20 21 22

  /**
   * Returns the code identifying the active form language.
   *
23 24
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
25 26 27 28
   *
   * @return string
   *   The form language code.
   */
29
  public function getFormLangcode(FormStateInterface $form_state);
30

31 32 33
  /**
   * Checks whether the current form language matches the entity one.
   *
34 35
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   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(FormStateInterface $form_state);
41

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

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

  /**
   * Returns the form entity.
   *
   * The form entity which has been used for populating form element defaults.
   *
65 66
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
67
   *
68
   * @return \Drupal\Core\Entity\EntityInterface
69 70
   *   The current form entity.
   */
71
  public function getEntity();
72 73 74 75 76 77

  /**
   * Sets the form entity.
   *
   * Sets the form entity which will be used for populating form element
   * defaults. Usually, the form entity gets updated by
78
   * \Drupal\Core\Entity\EntityFormInterface::submit(), however this may
79 80 81
   * be used to completely exchange the form entity, e.g. when preparing the
   * rebuild of a multi-step form.
   *
82
   * @param \Drupal\Core\Entity\EntityInterface $entity
83
   *   The entity the current form should operate upon.
84 85
   *
   * @return $this
86
   */
87
  public function setEntity(EntityInterface $entity);
88 89 90 91 92 93 94 95

  /**
   * 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.
   *
96
   * @see \Drupal\Core\Entity\EntityFormInterface::getEntity()
97 98 99
   *
   * @param array $form
   *   A nested array form elements comprising the form.
100 101
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
102
   *
103
   * @return \Drupal\Core\Entity\EntityInterface
104 105
   *   An updated copy of the form's entity object.
   */
106
  public function buildEntity(array $form, FormStateInterface $form_state);
107 108 109 110 111 112

  /**
   * Validates the submitted form values of the entity form.
   *
   * @param array $form
   *   A nested array form elements comprising the form.
113 114
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
115
   */
116
  public function validate(array $form, FormStateInterface $form_state);
117 118 119 120 121 122 123 124 125 126

  /**
   * 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.
127 128
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
129
   */
130
  public function submit(array $form, FormStateInterface $form_state);
131

132
  /**
133
   * Sets the string translation service for this form.
134
   *
135
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
136 137
   *   The translation manager.
   *
138
   * @return $this
139
   */
140
  public function setStringTranslation(TranslationInterface $string_translation);
141 142 143 144 145 146 147

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

152
}