public function TempStore::processForm in AJAX Comments 8
Update the temp store values while rebuilding a form, when necessary.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request object.
array $form: A form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state object.
bool $is_validating: Indicates if this method has been called from a form validation function.
Throws
\Drupal\user\TempStoreException
File
- src/
TempStore.php, line 139
Class
- TempStore
- A service to help store and retrieve data to be used across HTTP requests.
Namespace
Drupal\ajax_commentsCode
public function processForm(Request $request, $form, FormStateInterface $form_state, $is_validating = FALSE) {
$form_machine_name = $this->privateTempStore
->get('form_machine_name');
$form_build_info = $form_state
->getBuildInfo();
// If this form is being built through ajax, update the stored value
// of form_html_id.
if (Utility::isAjaxRequest($request)) {
if ($is_validating) {
$this
->setSelector('form_html_id', $form['form_html_id']['#value']);
$this->privateTempStore
->set('form_machine_name', $form_build_info['form_id']);
}
elseif ($form_build_info['form_id'] === $form_machine_name) {
$this
->setSelector('form_html_id', $form['form_html_id']['#value']);
}
}
}