3 namespace Drupal\inline_entity_form;
5 use Drupal\Core\Entity\EntityHandlerInterface;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Form\FormStateInterface;
10 * Defines the interface for inline form handlers.
12 interface InlineFormInterface extends EntityHandlerInterface {
15 * Gets the entity type managed by this handler.
17 * @return \Drupal\Core\Entity\EntityTypeInterface
20 public function getEntityType();
23 * Gets the entity type labels (singular, plural).
25 * @todo Remove when #1850080 lands and IEF starts requiring Drupal 8.1.x
28 * An array with two values:
29 * - singular: The lowercase singular label.
30 * - plural: The lowercase plural label.
32 public function getEntityTypeLabels();
35 * Gets the label of the given entity.
37 * @param \Drupal\Core\Entity\EntityInterface $entity
43 public function getEntityLabel(EntityInterface $entity);
46 * Gets the fields used to represent an entity in the IEF table.
48 * Modules can alter the output of this method through
49 * hook_inline_entity_form_table_fields_alter().
51 * @param string[] $bundles
52 * An array of allowed bundles for this widget.
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
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.
68 public function getTableFields($bundles);
71 * Checks whether tabledrag should be enabled for the given table.
73 * @param array $element
74 * The form element representing the IEF table.
77 * TRUE if tabledrag should be enabled, FALSE otherwise.
79 public function isTableDragEnabled($element);
82 * Builds the entity form.
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.
95 public function entityForm(array $entity_form, FormStateInterface $form_state);
98 * Validates the entity form.
100 * @param array $entity_form
102 * @param \Drupal\Core\Form\FormStateInterface $form_state
103 * The form state of the parent form.
105 public function entityFormValidate(array &$entity_form, FormStateInterface $form_state);
108 * Handles the submission of an entity form.
110 * @param array $entity_form
112 * @param \Drupal\Core\Form\FormStateInterface $form_state
113 * The form state of the parent form.
115 public function entityFormSubmit(array &$entity_form, FormStateInterface $form_state);
118 * Saves the given entity.
120 * @param \Drupal\Core\Entity\EntityInterface $entity
124 * Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
126 public function save(EntityInterface $entity);
129 * Delete permanently saved entities.
132 * An array of entity IDs.
133 * @param array $context
135 * - parent_entity_type: The type of the parent entity.
136 * - parent_entity: The parent entity.
138 public function delete($ids, $context);