function entity_browser_entity_form_reference_form_submit in Entity Browser 8.2
Same name and namespace in other branches
- 8 modules/entity_form/entity_browser_entity_form.module \entity_browser_entity_form_reference_form_submit()
Submits the form for adding existing entities.
Adds the specified entity to the IEF form state.
TODO see if we can get away without overriding entire IEF function.
Parameters
array $reference_form: The reference entity form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state of the parent form.
See also
inline_entity_form_reference_form_submit()
1 string reference to 'entity_browser_entity_form_reference_form_submit'
- entity_browser_entity_form_inline_entity_form_reference_form_alter in modules/
entity_form/ entity_browser_entity_form.module - Implements hook_inline_entity_form_reference_form_alter().
File
- modules/
entity_form/ entity_browser_entity_form.module, line 130 - Hook implementations for entity_browser_entity_form.module.
Code
function entity_browser_entity_form_reference_form_submit(array $reference_form, FormStateInterface $form_state) {
$ief_id = $reference_form['#ief_id'];
$form_values = NestedArray::getValue($form_state
->getValues(), $reference_form['#parents']);
$attach_entities = EntityBrowserElement::processEntityIds($form_values['entity_browser']['entity_ids']);
$entities =& $form_state
->get([
'inline_entity_form',
$ief_id,
'entities',
]);
// Determine the correct weight of the new element.
$weight = 0;
if ($entities) {
$weight = max(array_keys($entities)) + 1;
}
foreach ($attach_entities as $attach_entity) {
$entities[] = [
'entity' => $attach_entity,
'weight' => $weight,
'form' => NULL,
'needs_save' => FALSE,
];
$weight++;
}
$form_state
->set([
'inline_entity_form',
$ief_id,
'entities',
], $entities);
// In some rare cases entity_ids keeps values of selected entities which then
// causes problems in subsequent selections. Let's make sure it is empty and
// ready for next usage of entity browser.
$form_state
->setValueForElement($reference_form['entity_browser']['entity_ids'], '');
$input =& $form_state
->getUserInput();
NestedArray::unsetValue($input, array_merge($reference_form['#parents'], [
'entity_browser',
'entity_ids',
]));
}