protected function InlineEntityFormBase::prepareFormState in Inline Entity Form 8
Prepares the form state for the current widget.
Parameters
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
\Drupal\Core\Field\FieldItemListInterface $items: The field values.
bool $translating: Whether there's a translation in progress.
1 call to InlineEntityFormBase::prepareFormState()
- InlineEntityFormComplex::formElement in src/
Plugin/ Field/ FieldWidget/ InlineEntityFormComplex.php - Returns the form for a single field widget.
File
- src/
Plugin/ Field/ FieldWidget/ InlineEntityFormBase.php, line 377
Class
- InlineEntityFormBase
- Inline entity form widget base class.
Namespace
Drupal\inline_entity_form\Plugin\Field\FieldWidgetCode
protected function prepareFormState(FormStateInterface $form_state, FieldItemListInterface $items, $translating = FALSE) {
$widget_state = $form_state
->get([
'inline_entity_form',
$this->iefId,
]);
if (empty($widget_state)) {
$widget_state = [
'instance' => $this->fieldDefinition,
'form' => NULL,
'delete' => [],
'entities' => [],
];
// Store the $items entities in the widget state, for further manipulation.
foreach ($items
->referencedEntities() as $delta => $entity) {
// Display the entity in the correct translation.
if ($translating) {
$entity = TranslationHelper::prepareEntity($entity, $form_state);
}
$widget_state['entities'][$delta] = [
'entity' => $entity,
'weight' => $delta,
'form' => NULL,
'needs_save' => $entity
->isNew(),
];
}
$form_state
->set([
'inline_entity_form',
$this->iefId,
], $widget_state);
}
}