function inline_entity_form_entity_form_submit in Inline Entity Form 7
Submits an entity form.
Note that at this point the entity is not yet saved, since the user might still decide to cancel the parent form.
Parameters
$entity_form: The form of the entity being managed inline.
$form_state: The form state of the parent form.
1 string reference to 'inline_entity_form_entity_form_submit'
- inline_entity_form_entity_form in ./
inline_entity_form.module - Wraps and returns the entity form provided by the passed-in controller.
File
- ./
inline_entity_form.module, line 994 - 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_entity_form_submit($entity_form, &$form_state) {
$ief_id = $entity_form['#ief_id'];
$instance = $form_state['inline_entity_form'][$ief_id]['instance'];
// Instantiate the controller and validate the form.
$controller = inline_entity_form_get_controller($instance);
$controller
->entityFormSubmit($entity_form, $form_state);
inline_entity_form_cleanup_entity_form_state($entity_form, $form_state);
if (in_array($entity_form['#op'], array(
'add',
'clone',
))) {
// Determine the correct weight of the new element.
$weight = 0;
if (!empty($form_state['inline_entity_form'][$ief_id]['entities'])) {
$weight = max(array_keys($form_state['inline_entity_form'][$ief_id]['entities'])) + 1;
}
// Add the entity to form state, mark it for saving, and close the form.
$form_state['inline_entity_form'][$ief_id]['entities'][] = array(
'entity' => $entity_form['#entity'],
'weight' => $weight,
'form' => NULL,
'needs_save' => TRUE,
);
}
else {
$delta = $entity_form['#ief_row_delta'];
$form_state['inline_entity_form'][$ief_id]['entities'][$delta]['entity'] = $entity_form['#entity'];
$form_state['inline_entity_form'][$ief_id]['entities'][$delta]['needs_save'] = TRUE;
}
}