EntityFormInterface.php 4.25 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\StringTranslation\TranslationInterface;
13

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

  /**
   * 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.
   */
28
  public function getFormLangcode(array &$form_state);
29

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

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

51
  /**
52
   * Returns the operation identifying the form.
53 54 55 56 57 58 59 60 61 62 63 64 65 66
   *
   * @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.
   *
   * @param array $form_state
   *   An associative array containing the current state of the form.
   *
67
   * @return \Drupal\Core\Entity\EntityInterface
68 69
   *   The current form entity.
   */
70
  public function getEntity();
71 72 73 74 75 76

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

  /**
   * 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.
   *
95
   * @see \Drupal\Core\Entity\EntityFormInterface::getEntity()
96 97 98 99 100 101
   *
   * @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.
   *
102
   * @return \Drupal\Core\Entity\EntityInterface
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
   *   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);

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

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

151
}