function inline_entity_form_reference_form_submit in Inline Entity Form 7
Same name and namespace in other branches
- 8 inline_entity_form.module \inline_entity_form_reference_form_submit()
Submits the form for adding existing entities.
Adds the specified entity to the IEF form state.
Parameters
$reference_form: The reference entity form.
$form_state: The form state of the parent form.
1 string reference to 'inline_entity_form_reference_form_submit'
- inline_entity_form_reference_form in ./
inline_entity_form.module - Provides the form for adding existing entities through an autocomplete field.
File
- ./
inline_entity_form.module, line 1151 - 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_reference_form_submit($reference_form, &$form_state) {
$ief_id = $reference_form['#ief_id'];
$entity_type = $reference_form['#entity_type'];
$form_values = drupal_array_get_nested_value($form_state['values'], $reference_form['#parents']);
$attach_entity = entity_load_single($entity_type, $form_values['entity_id']);
// 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;
}
$form_state['inline_entity_form'][$ief_id]['entities'][] = array(
'entity' => $attach_entity,
'weight' => $weight,
'form' => NULL,
'needs_save' => FALSE,
);
}