function entityconnect_form_alter in Entity connect 8.2
Same name and namespace in other branches
- 7.2 entityconnect.module \entityconnect_form_alter()
- 7 entityconnect.module \entityconnect_form_alter()
Implements hook_form_alter().
File
- ./
entityconnect.module, line 80 - Contains entityconnect.module.
Code
function entityconnect_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Get the cache from the id and set the form state if this is a child form.
$request = \Drupal::request();
if (!empty($request->query
->get('build_cache_id'))) {
$cid = $request->query
->get('build_cache_id');
$cache_data = \Drupal::getContainer()
->get('entityconnect.cache')
->get($cid);
if (!empty($request->query
->get('child'))) {
$form_state
->set('#entityconnect_child_form', [
$cid => $cache_data,
]);
}
if (!empty($request->query
->get('return')) && !empty($cache_data) && $cache_data['form']['#form_id'] == $form_id) {
$request->query
->remove('build_cache_id');
EntityconnectFormUtils::returnFormAlter($form, $form_state, $cache_data);
\Drupal::getContainer()
->get('entityconnect.cache')
->delete($cid);
}
}
// If this form is a child form let's add alter for that purpose
// Note that we are doing this here because when we return to a form it gets
// rebuilt so this will get caught in the rebuilt.
if ($cache = $form_state
->get('#entityconnect_child_form')) {
EntityconnectFormUtils::childFormAlter($form, $form_state, $form_id, key($cache));
}
// Adds entity connect buttons to any ref fields in the form.
EntityconnectFormUtils::entityFormAlter($form, $form_state);
}