You are here

function opigno_module_views_form_opigno_activities_bank_lp_interface_default_ajax_callback in Opigno module 8

Same name and namespace in other branches
  1. 3.x opigno_module.module \opigno_module_views_form_opigno_activities_bank_lp_interface_default_ajax_callback()

Implements opigno_module_views_form_opigno_activities_bank_lp_interface_default_ajax_callback().

1 string reference to 'opigno_module_views_form_opigno_activities_bank_lp_interface_default_ajax_callback'
opigno_module_form_views_form_opigno_activities_bank_lp_interface_default_alter in ./opigno_module.module
Ajaxify activity bank form.

File

./opigno_module.module, line 612
Contains opigno_module.module.

Code

function opigno_module_views_form_opigno_activities_bank_lp_interface_default_ajax_callback($form, FormStateInterface &$form_state) {
  $form_id = $form['form_id']['#value'];
  $render_selector = 'ajaxify_submit_form_' . $form_id;

  // Used to display results of drupal_set_message() calls.
  $messages = StatusMessages::renderMessages(NULL);

  // Create AJAX Response object.
  $response = new AjaxResponse();
  $output = [];
  if ($form_state
    ->getErrors()) {
    $output[] = $messages;
    $response
      ->addCommand(new AppendCommand($render_selector, $output));
    $command = new SettingsCommand([
      'closeActivityBankPanel' => FALSE,
    ], TRUE);
  }
  else {

    // Default reload the page printing the status message.
    $output[] = $messages;
    $output[] = $form;
    $response
      ->addCommand(new HtmlCommand($render_selector, $output));
    $command = new SettingsCommand([
      'closeActivityBankPanel' => TRUE,
    ], TRUE);
  }
  $route_name = \Drupal::routeMatch()
    ->getRouteName();
  $opigno_module = \Drupal::routeMatch()
    ->getParameter('opigno_module');
  if ($opigno_module && $route_name == 'opigno_module.activities_bank') {
    $url = Url::fromRoute('opigno_module.modules', [
      'opigno_module' => $opigno_module
        ->id(),
    ]);
    $command = new RedirectCommand($url
      ->toString());
    $response
      ->addCommand($command);
  }
  $response
    ->addCommand($command);
  return $response;
}