Skip to content

Instantly share code, notes, and snippets.

@alexey-kuznetsov
Created November 3, 2017 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexey-kuznetsov/279dd42c293bae45fc000fb32842db57 to your computer and use it in GitHub Desktop.
Save alexey-kuznetsov/279dd42c293bae45fc000fb32842db57 to your computer and use it in GitHub Desktop.
Working ajax form with multiple commands in response
/**
* AJAX process step
*/
public function processStep(array &$form, FormStateInterface $form_state) {
$ajax_response = new AjaxResponse();
$ajax_response->addCommand(new ReplaceCommand(
'h1.page-title',
'<h1 class="page-title">' . $this->getTitle() . '</h1>'
));
// This is necessary to attach settings
$elements = $form;
\Drupal::service('renderer')->renderRoot($elements);
$ajax_response->addCommand(new SettingsCommand(
$elements['#attached']['drupalSettings'],
TRUE
));
$ajax_response->addCommand(new ReplaceCommand(
'#stepped-search-wrapper',
\Drupal::service('renderer')->renderRoot($form)
));
return $ajax_response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment