You are here

function inline_entity_form_close_all_forms in Inline Entity Form 7

Same name and namespace in other branches
  1. 8 inline_entity_form.module \inline_entity_form_close_all_forms()

Closes all open IEF forms.

Recurses and closes open forms in nested IEF widgets as well.

Parameters

$elements: An array of form elements containing entity forms.

$form_state: The form state of the parent form.

1 call to inline_entity_form_close_all_forms()
inline_entity_form_close_child_forms in ./inline_entity_form.module
Button #submit callback: Closes all open child forms in the IEF widget.

File

./inline_entity_form.module, line 1433
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_close_all_forms($elements, &$form_state) {

  // Recurse through all children.
  foreach (element_children($elements) as $key) {
    if (!empty($elements[$key])) {
      inline_entity_form_close_all_forms($elements[$key], $form_state);
    }
  }
  if (!empty($elements['#ief_id'])) {
    $ief_id = $elements['#ief_id'];

    // Close the main form.
    $form_state['inline_entity_form'][$ief_id]['form'] = NULL;

    // Close the row forms.
    foreach ($form_state['inline_entity_form'][$ief_id]['entities'] as &$value) {
      $value['form'] = NULL;
    }
  }
}