function inline_entity_form_cleanup_entity_form_state in Inline Entity Form 7
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['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.
3 calls to inline_entity_form_cleanup_entity_form_state()
- 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.
- inline_entity_form_entity_form_submit in ./
inline_entity_form.module - Submits an entity form.
File
- ./
inline_entity_form.module, line 1564 - Provides a widget for inline management (creation, modification, removal) of referenced entities. The primary use case is the parent -> children one (for example, order -> line items), where the child entities are never managed outside the…
Code
function inline_entity_form_cleanup_entity_form_state($entity_form, &$form_state) {
$info = entity_get_info($entity_form['#entity_type']);
if (empty($info['fieldable'])) {
// The entity type is not fieldable, nothing to cleanup.
return;
}
list(, , $bundle) = entity_extract_ids($entity_form['#entity_type'], $entity_form['#entity']);
$instances = field_info_instances($entity_form['#entity_type'], $bundle);
foreach ($instances as $instance) {
$field_name = $instance['field_name'];
if (!empty($entity_form[$field_name]['#parents'])) {
$parents = $entity_form[$field_name]['#parents'];
array_pop($parents);
$langcode = $entity_form[$field_name]['#language'];
$field_state = array();
field_form_set_state($parents, $field_name, $langcode, $form_state, $field_state);
}
}
}