public static function EntityconnectFormUtils::childFormSubmit in Entity connect 8.2
Form API callback: Submit callback for child form.
Sets submit button on child create form.
On submission of a child form we set: the target_id in the cache entry the redirect to our redirect page.
Parameters
array $form: Child form.
\Drupal\Core\Form\FormStateInterface $form_state: Child form state.
File
- src/
EntityconnectFormUtils.php, line 420
Class
- EntityconnectFormUtils
- Contains form alter, callbacks and utility methods for entityconnect.
Namespace
Drupal\entityconnectCode
public static function childFormSubmit(array $form, FormStateInterface $form_state) {
$cache_id = $form_state
->getValue('parent_build_cache_id');
if ($cache_id && ($cache_data = \Drupal::getContainer()
->get('entityconnect.cache')
->get($cache_id))) {
$entity = $form_state
->getFormObject()
->getEntity();
if ($entity) {
$cache_data['target_id'] = $entity
->id();
}
else {
$entity_type = $cache_data['target_entity_type'];
$data = [
'form' => &$form,
'form_state' => &$form_state,
'entity_type' => $entity_type,
'data' => &$cache_data,
];
\Drupal::moduleHandler()
->alter('entityconnect_child_form_submit', $data);
}
\Drupal::getContainer()
->get('entityconnect.cache')
->set($cache_id, $cache_data);
$form_state
->setRedirect('entityconnect.return', [
'cache_id' => $cache_id,
]);
}
}