public static function EntityInlineForm::submitCleanFormState in Inline Entity Form 8
Cleans up the form state for a submitted entity form.
After field_attach_submit() has run and the form has been closed, the form state still contains field data in $form_state->get('field'). Unless that data is removed, the next form with the same #parents (reopened add form, for example) will contain data (i.e. uploaded files) from the previous form.
Parameters
$entity_form: The entity form.
$form_state: The form state of the parent form.
2 calls to EntityInlineForm::submitCleanFormState()
- inline_entity_form_cleanup_form_state in ./
inline_entity_form.module - Button #submit callback: Cleans up form state for a closed entity form.
- inline_entity_form_cleanup_row_form_state in ./
inline_entity_form.module - Button #submit callback: Cleans up form state for a closed entity row form.
File
- src/
Form/ EntityInlineForm.php, line 324
Class
- EntityInlineForm
- Generic entity inline form handler.
Namespace
Drupal\inline_entity_form\FormCode
public static function submitCleanFormState(&$entity_form, FormStateInterface $form_state) {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $entity_form['#entity'];
$bundle = $entity
->bundle();
/** @var \Drupal\Core\Field\FieldDefinitionInterface[] $instances */
$instances = \Drupal::service('entity_field.manager')
->getFieldDefinitions($entity_form['#entity_type'], $bundle);
foreach ($instances as $instance) {
$field_name = $instance
->getName();
if (!empty($entity_form[$field_name]['#parents'])) {
$parents = $entity_form[$field_name]['#parents'];
array_pop($parents);
if (!empty($parents)) {
$field_state = [];
WidgetBase::setWidgetState($parents, $field_name, $form_state, $field_state);
}
}
}
}