Commit 11fc96e7 authored by Omkar Deshpande's avatar Omkar Deshpande
Browse files

Issue #3249059 by Santhosh-Kumar-Rengasamy: Shows old/wrong messages - Caching...

Issue #3249059 by Santhosh-Kumar-Rengasamy: Shows old/wrong messages - Caching JS issue with status message
parent ee78ea08
Loading
Loading
Loading
Loading
+10 −5
Changes for toastr.module: 10 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,13 @@ use Drupal\toastr\Form\ToastrSettingsForm;
 * Implements hook_page_attachments().
 */
function toastr_page_attachments(array &$attachments) {
  $attachments['#attached']['library'][] = 'toastr/messages';
}

/**
 * Implements hook_js_settings_alter().
 */
function toastr_js_settings_alter(array &$settings, \Drupal\Core\Asset\AttachedAssetsInterface $assets) {
  // Get all the Drupal status messages, so they do not appear anywhere else.
  $messages = \Drupal::messenger()->deleteAll();
  if (!empty($messages)) {
@@ -16,10 +23,8 @@ function toastr_page_attachments(array &$attachments) {
    foreach ($keys as $key) {
      $settings[$key] = is_null($config->get($key)) ? $default_settings[$key] : $config->get($key);
    }
    $attachments['#attached']['drupalSettings']['toastr'] = [];
    $attachments['#attached']['drupalSettings']['toastr']['messages'] = $messages;
    $attachments['#attached']['drupalSettings']['toastr']['settings'] = $settings;
    // Unconditionally attach an asset to the page.
    $attachments['#attached']['library'][] = 'toastr/messages';
    $settings['toastr'] = [];
    $settings['toastr']['messages'] = $messages;
    $settings['toastr']['settings'] = $settings;
  }
}