You are here

function fancy_login_user_login_block_ajax_callback in Fancy Login 3.0.x

Same name and namespace in other branches
  1. 8.2 fancy_login.module \fancy_login_user_login_block_ajax_callback()
  2. 7.3 fancy_login.module \fancy_login_user_login_block_ajax_callback()
  3. 7.2 fancy_login.module \fancy_login_user_login_block_ajax_callback()

Ajax callback function for fancy_login_user_login_block submit button.

1 string reference to 'fancy_login_user_login_block_ajax_callback'
fancy_login_form_alter in ./fancy_login.module
Implements hook_form_alter().

File

./fancy_login.module, line 20
Holds hooks for the Fancy Login module.

Code

function fancy_login_user_login_block_ajax_callback(array $form, FormStateInterface $form_state) {
  global $base_url;
  $response = new AjaxResponse();
  $messenger = \Drupal::messenger();
  $message_data = $messenger
    ->all();

  // Check to see if there were any errors with the form submission.
  if (!isset($message_data['error'])) {
    $config = \Drupal::config('fancy_login.settings');
    if ($config
      ->get('no_redirect')) {
      $messenger
        ->addStatus(t('You have been successfully logged in. Please wait while the page is refreshed.'));
      $response
        ->addCommand(new FancyLoginRefreshPageCommand(TRUE));
    }
    else {
      $messenger
        ->addStatus(t('You have been successfully logged in. Please wait while you are redirected.'));
      $dest = $base_url . $form_state
        ->getRedirect();
      $response
        ->addCommand(new FancyLoginRedirectCommand(TRUE, $dest));
    }
  }
  $renderer = \Drupal::service('renderer');
  $messages = [
    '#type' => 'status_messages',
  ];
  $messages = $renderer
    ->renderRoot($messages);
  $selector = '#fancy_login_user_login_block_wrapper';
  $response
    ->addCommand(new AppendCommand($selector, $messages));
  return $response;
}