fe56c160f73371424edca93d5bad03347407b5b4
[yaffs-website] / InlineFormInterface.php
1 <?php
2
3 namespace Drupal\inline_entity_form;
4
5 use Drupal\Core\Entity\EntityHandlerInterface;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Form\FormStateInterface;
8
9 /**
10  * Defines the interface for inline form handlers.
11  */
12 interface InlineFormInterface extends EntityHandlerInterface {
13
14   /**
15    * Gets the entity type managed by this handler.
16    *
17    * @return \Drupal\Core\Entity\EntityTypeInterface
18    *   The entity type.
19    */
20   public function getEntityType();
21
22   /**
23    * Gets the entity type labels (singular, plural).
24    *
25    * @todo Remove when #1850080 lands and IEF starts requiring Drupal 8.1.x
26    *
27    * @return array
28    *   An array with two values:
29    *     - singular: The lowercase singular label.
30    *     - plural: The lowercase plural label.
31    */
32   public function getEntityTypeLabels();
33
34   /**
35    * Gets the label of the given entity.
36    *
37    * @param \Drupal\Core\Entity\EntityInterface $entity
38    *   The given entity.
39    *
40    * @return string
41    *   The entity label.
42    */
43   public function getEntityLabel(EntityInterface $entity);
44
45   /**
46    * Gets the fields used to represent an entity in the IEF table.
47    *
48    * Modules can alter the output of this method through
49    * hook_inline_entity_form_table_fields_alter().
50    *
51    * @param string[] $bundles
52    *   An array of allowed bundles for this widget.
53    *
54    * @return array
55    *   An array of fields keyed by field name. Each field is represented by an
56    *   associative array containing the following keys:
57    *   - type: 'label', 'field' or 'callback'.
58    *   - label: the title of the table field's column in the IEF table.
59    *   - weight: the sort order of the column in the IEF table.
60    *   - display_options: (optional) used for 'field' type table fields, an
61    *     array of display settings. See EntityViewBuilderInterface::viewField().
62    *   - callback: for 'callback' type table fields, a callable that returns a
63    *     renderable array.
64    *   - callback_arguments: (optional) an array of additional arguments to pass
65    *     to the callback. The entity and the theme variables are always passed
66    *     as as the first two arguments.
67    */
68   public function getTableFields($bundles);
69
70   /**
71    * Checks whether tabledrag should be enabled for the given table.
72    *
73    * @param array $element
74    *   The form element representing the IEF table.
75    *
76    * @return bool
77    *   TRUE if tabledrag should be enabled, FALSE otherwise.
78    */
79   public function isTableDragEnabled($element);
80
81   /**
82    * Builds the entity form.
83    *
84    * @param array $entity_form
85    *   The entity form, containing the following basic properties:
86    *   - #entity: The entity for the current entity form.
87    *   - #op: The form operation. 'add' or 'edit'.
88    *   - #form_mode: The form mode used to display the entity form.
89    *   - #parents: Identifies the position of the entity form in the overall
90    *     parent form, and identifies the location where the field values are
91    *     placed within $form_state->getValues().
92    * @param \Drupal\Core\Form\FormStateInterface $form_state
93    *   The form state of the parent form.
94    */
95   public function entityForm(array $entity_form, FormStateInterface $form_state);
96
97   /**
98    * Validates the entity form.
99    *
100    * @param array $entity_form
101    *   The entity form.
102    * @param \Drupal\Core\Form\FormStateInterface $form_state
103    *   The form state of the parent form.
104    */
105   public function entityFormValidate(array &$entity_form, FormStateInterface $form_state);
106
107   /**
108    * Handles the submission of an entity form.
109    *
110    * @param array $entity_form
111    *   The entity form.
112    * @param \Drupal\Core\Form\FormStateInterface $form_state
113    *   The form state of the parent form.
114    */
115   public function entityFormSubmit(array &$entity_form, FormStateInterface $form_state);
116
117   /**
118    * Saves the given entity.
119    *
120    * @param \Drupal\Core\Entity\EntityInterface $entity
121    *   The entity.
122    *
123    * @return int
124    *   Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
125    */
126   public function save(EntityInterface $entity);
127
128   /**
129    * Delete permanently saved entities.
130    *
131    * @param int[] $ids
132    *   An array of entity IDs.
133    * @param array $context
134    *   Available keys:
135    *   - parent_entity_type: The type of the parent entity.
136    *   - parent_entity: The parent entity.
137    */
138   public function delete($ids, $context);
139
140 }