I think it would be cool to allow admins to choose whether or not to allow users to dismiss site alerts.

Example:

https://www.drupal.org/project/sitewide_alert this module has a checkbox to make the site alert dismissable.

CommentFileSizeAuthor
#68 Screenshot 2023-02-20 at 12.17.25 pm.png12.28 KBnadim hossain
#68 Screenshot 2023-02-20 at 12.17.12 pm.png36.08 KBnadim hossain
#67 3156557-67.patch24.71 KBnadim hossain
#63 3156557-63.patch17.14 KBnadim hossain
#60 3156557-60.patch3.64 KBanoopsingh92
#54 3156557-55.patch15.34 KBtjh
#53 3156557-53.patch13.5 KBtjh
#51 3156557-51.patch24.7 KBpcate
#49 site-alert-original.png9.61 KBpfrenssen
#48 site-alert-icon-regression.png12.24 KBpfrenssen
#41 3156557-41.patch25.22 KBpcate
#37 code.png27.76 KBntaylor1994
#34 interdiff_3156557-29-3156557-34.txt6.35 KBpcate
#34 3156557-34.patch25.19 KBpcate
#33 Screenshot 2020-09-14 at 09.26.09.png8.09 KBnejcramsak
#29 3156557-29.patch18.83 KBpcate
#28 3156557-28.patch19 KBpcate
#27 interdiff_3156557-24-3156557-27.txt12.42 KBpcate
#27 3156557-27.patch20.05 KBpcate
#26 interdiff_3156557-24-3156557-26.txt12.66 KBpcate
#26 3156557-26.patch19.67 KBpcate
#24 interdiff_3156557-22-3156557-24.txt2.1 KBpcate
#24 3156557-24.patch15.53 KBpcate
#22 interdiff_3156557-19-3156557-22.txt9.37 KBpcate
#22 3156557-22.patch14.82 KBpcate
#19 interdiff_3156557-16-3156557-19.txt2.47 KBpcate
#19 3156557-19.patch11.17 KBpcate
#16 interdiff_3156557-15-3156557-16.txt7.7 KBpcate
#16 3156557-16.patch10.73 KBpcate
#15 3156557-15.patch5.54 KBpcate
#12 3156557-12.patch5.71 KBnejcramsak
#12 interdiff_10-12.txt4.22 KBnejcramsak
#10 3156557-10.patch5.2 KBnejcramsak
#10 interdiff_8-10.txt4.26 KBnejcramsak
#8 3156557-8.patch4.89 KBpavnish
#8 interdiff_2_8.txt549 bytespavnish
#6 interdiff_2_5.txt546 bytespavnish
#6 3156557-5.patch5.32 KBpavnish
#5 site_alert.png6.97 KBpavnish
#2 3156557_2.patch4.87 KBnejcramsak

Issue fork site_alert-3156557

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ntaylor1994 created an issue. See original summary.

nejcramsak’s picture

Status: Active » Needs review
StatusFileSize
new4.87 KB

Hi, i created a patch for this. Needs review.

Status: Needs review » Needs work

The last submitted patch, 2: 3156557_2.patch, failed testing. View results

ntaylor1994’s picture

When I applied the patch, I needed to clear cache or else I got a website encounter an error when going to the site alert page.

Now when I check the box and save, the box isnt checked when I go back and look.

On a fresh install it stays checked, and I see the new div.dismissable, but it has no height, nothing in it, and doesnt hide the alert when clicked.

pavnish’s picture

StatusFileSize
new6.97 KB

@ntaylor1994 i have check this is working fine for me for reference please find the screenshot.

pavnish’s picture

Status: Needs work » Needs review
StatusFileSize
new5.32 KB
new546 bytes

@nejcramsak oh ! some more test get failed looking into this im going to setup Behat on my local and then test if success will upload the patch for the same

Status: Needs review » Needs work

The last submitted patch, 6: 3156557-5.patch, failed testing. View results

pavnish’s picture

Status: Needs work » Needs review
StatusFileSize
new549 bytes
new4.89 KB

@nejcramsak I have fixed the test case in my local Please review I have remove the extra code also tested with that no functionality get backed.

nejcramsak’s picture

Status: Needs review » Needs work

Hi @pavnish, i tested the patch and the tests seem to work, but after applying the patch if there are any site alerts already on the page, i needed to clear the cache to see the checkbox.
Also if there are multiple site alerts but only one of them is checked as dismissable, when that one is dismissed all of the others seem to disappear as well, instead of only the one that is checked.

nejcramsak’s picture

Status: Needs work » Needs review
StatusFileSize
new4.26 KB
new5.2 KB

I fixed the issue where all the alerts would be dismissed instead of only the one being dismissed. Also created an update function to add the field, so it would work properly.

pcate’s picture

There are accessibility issues with using a div for the dismiss button. I recommend using an actual button element. There should be visually hidden text for screen readers that labels the button as well.

Also, in keeping with Drupal CSS standards, I would use a js- prefixed class on the button to use as the click handler selector. This more clearly indicates that that the selector is being used in JavaScript and should not be removed. It also decouples the styling CSS markup from that required for the JavaScript.

I'd recommend something like:

<button type="button" class="js-site-alert-dismiss dismiss">
    <span class="dismiss__icon" aria-hidden="true"></span>
    <span class="visually-hidden">{{ 'Dismiss alert'|t }}</span>
</button>

with the icon CSS being moved to the .dismiss__icon element.

nejcramsak’s picture

StatusFileSize
new4.22 KB
new5.71 KB

Hi, thanks for pointing that out, i changed the div to a button element. I also added the update hook to .install file instead of .module.

pcate’s picture

@nejcramsak the JavaScript doesn't load if the block Timeout setting is set to 0. Appears to be from this code:

// Attach the JS code to refresh the site alerts when a timeout is
    // configured.
    $timeout = $this->getConfiguration()['timeout'];
    if ($timeout > 0 || $workaround_needed) {
      $build['#attached'] = [
        'library' => ['site_alert/drupal.site_alert'],
        'drupalSettings' => [
          'siteAlert' => [
            'timeout' => $timeout,
            'workaround_needed' => $workaround_needed,
          ],
        ],
      ];
    }

in the SiteAlertBlock.php file.

pcate’s picture

Status: Needs review » Needs work
pcate’s picture

StatusFileSize
new5.54 KB

Re-rolled patch #12 to work with latest dev version. No other changes.

pcate’s picture

StatusFileSize
new10.73 KB
new7.7 KB

After more testing I found some additional issues.

  1. Alert un-hide when timeout refreshed alert via AJAX.
  2. Dismiss button didn't have label for screen readers.
  3. Hidden alerts were momentary visible on page load because the alert had loaded before the 'display: none' CSS could be applied via JavaScript.
  4. Did not work in IE 11 due to use of Array.includes method.

I needed this for a client, so I refactored with the following changes.

Twig template

  • Added screenreader-only label text for dismiss button.
  • Switch to template attributes object for applying root level markup attributes.
  • Replaced ID attribute with 'data-site-alert-id' attribute. This was mainly to prevent future issues of duplicate Id's.
  • For all dismissable alerts, applied the core 'hidden' class by default to the alert. This prevented issue #3 as the JavaScript now removes the class if it should be visible.



JavaScript

  • Switched from multiple session storage keys for each alert, to one JSON encoded Object. This was mainly to provide a central cache store for managing the visibility of multiple alerts easier. This change also removed the use of the Array.includes method that cause IE 11 errors.
  • Used button value property to pass the alert Id that should be dismissed.
  • Replaced inline 'display:none' CSS with add/removing the core 'hidden' visibility class.



Block

  • Loaded JavaScript if dismiss option is turned on for alert. (Address comment #13 issue.)



CSS

  • Tweaked some CSS of dismiss icon and changed property order to be consistent.


As I said I needed this working for a client, but wanted to contribute back the work I did in case it's useful. Feel free to cherrypick any of the changes.

pcate’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 16: 3156557-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

pcate’s picture

StatusFileSize
new11.17 KB
new2.47 KB

Fixed issue with scheduled alerts not rendering with ID,.

pcate’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 19: 3156557-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

pcate’s picture

StatusFileSize
new14.82 KB
new9.37 KB

Updated patch. I moved the dismiss javascript code to its own separate file so it could be loaded only when an alert is dismissible. This allowed a revert of the

if ($timeout > 0 || $workaround_needed || $alert->getDismissible()) {

logic that I think was causing tests to fail.

pcate’s picture

Status: Needs work » Needs review
pcate’s picture

StatusFileSize
new15.53 KB
new2.1 KB

Minor update to patch to fix some PHP CS warnings found in tests.

pcate’s picture

Assigned: Unassigned » pcate
Status: Needs review » Needs work

Found an issue where some JS wasn't being loaded correctly if the timeout was set to 0. Will work on a fix.

pcate’s picture

StatusFileSize
new19.67 KB
new12.66 KB
pcate’s picture

StatusFileSize
new20.05 KB
new12.42 KB
pcate’s picture

StatusFileSize
new19 KB
pcate’s picture

StatusFileSize
new18.83 KB
pcate’s picture

Patch #29 should work now. I encountered an issue where the CSS wasn't being loaded in cases were the JS was loaded, since the two were in the same library. I split out the CSS and JS into separate libraries to resolve the issue.

pcate’s picture

Status: Needs work » Needs review
pcate’s picture

Assigned: pcate » Unassigned
nejcramsak’s picture

Status: Needs review » Needs work
StatusFileSize
new8.09 KB

Hi, i reviewed the patch and it applies. The dismissing part of the patch works, but i still encountered a problem where CSS wasn't fully loaded. I tried it without a clean install and on a clean install and tried flushing the cache on both instances, but the CSS wasn't loaded.

pcate’s picture

StatusFileSize
new25.19 KB
new6.35 KB

I think I found the missing CSS issue. I also went ahead and added a JavaScript test.

pcate’s picture

Status: Needs work » Needs review
nejcramsak’s picture

Status: Needs review » Reviewed & tested by the community

I tested the patch and it works. The CSS issue is now fixed and the dismissing worked great so setting this as RTBC.

ntaylor1994’s picture

StatusFileSize
new27.76 KB

Im not seeing the dismiss button. Also, when i check dismissable and save then go back and check, the checkbox is not marked anymore.

pcate’s picture

@ntaylor1994 After applying the patch did you run a database update and clear all caches?

pfrenssen’s picture

With this patch I am seeing icons pop up where there were none before. I think it is this change causing it:

 .site-alert .severity-medium {
-  background: #f3eaac;
+  background-color: #f3eaac;
 }

I agree that this is more correct, and it was probably the intention to show the icons all along, but let's try not to cause any visual changes that are not related to this issue. We can handle this in a separate issue.

I only had a quick look, it might be caused also by some custom theming in my project.

ntaylor1994’s picture

I cannot apply a patch anymore:
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2020-09-14/3156557-34_0.patch

This is in my composer.patches file:
"drupal/site_alert": {
"dismissible": "https://www.drupal.org/files/issues/2020-07-01/site_alert-responsive-man..."
}

drupal 8.8.10 php 7.3.12

pcate’s picture

StatusFileSize
new25.22 KB

let's try not to cause any visual changes that are not related to this issue.

Updated patch to revert from using background-color to the original background

pcate’s picture

@pfrenssen let me know if #41 fixes the icons showing where they weren't before.

pcate’s picture

I created an issue branch with patch #41 applied to it in case it's easier to review the changes in GitLab: https://git.drupalcode.org/issue/site_alert-3156557/-/compare/8.x-1.x......

jasonluttrell’s picture

#41 works for me, though I cannot say anything about icons appearing in the wrong place. It seems RTBC.

ntaylor1994’s picture

When do you think this can go live?

pcate’s picture

@pfrenssen would it be possible to get a new release (even a dev one) that has this and some of the other RTBC issues added?

pfrenssen’s picture

Thanks for the callout, I agree that it would be good moment to go through the RTBC queue.

pfrenssen’s picture

Assigned: Unassigned » pfrenssen
Status: Reviewed & tested by the community » Needs work
StatusFileSize
new12.24 KB

I'm still seeing some visual changes to the icons when applying this patch on one of my projects. This project has replaced the original icon with something that better fits the design of this particular site. I think this is probably common since the standard icon is quite old fashioned. Changes I am seeing:

  1. There are now 2 icons appearing.
  2. Space between icon and text increases quite a lot.
  3. Overall size and height of the alert increases.

It looks like this is probably avoidable if we avoid making any unnecessary changes to the CSS. The HTML is almost identical, save from the addition of a few classes which should be OK.

Before

After

I'll have a go at this to see if we can preserve the CSS. We should try our best not to affect existing designs on a minor update.

pfrenssen’s picture

StatusFileSize
new9.61 KB
pfrenssen’s picture

Assigned: pfrenssen » Unassigned

The visual regression is not caused by the CSS, but by altering the way the JS and CSS libraries work. The patch splits off part of the site_alert library into a new library called site_alert_ajax but this is causing the regression. If I revert this change by applying the following patch the alerts appear normal again:

diff --git a/site_alert.libraries.yml b/site_alert.libraries.yml
index b50902f..6a12d8d 100644
--- a/site_alert.libraries.yml
+++ b/site_alert.libraries.yml
@@ -3,9 +3,6 @@ drupal.site_alert:
   css:
     theme:
       css/site_alert.css: {}
-
-drupal.site_alert_ajax:
-  version: VERSION
   js:
     js/site_alert.js: {}
   dependencies:
diff --git a/src/Plugin/Block/SiteAlertBlock.php b/src/Plugin/Block/SiteAlertBlock.php
index dce9bc3..fb2fdf5 100644
--- a/src/Plugin/Block/SiteAlertBlock.php
+++ b/src/Plugin/Block/SiteAlertBlock.php
@@ -152,11 +152,13 @@ class SiteAlertBlock extends BlockBase implements ContainerFactoryPluginInterfac
     $timeout = $this->getConfiguration()['timeout'];
 
     if ($timeout > 0 || $workaround_needed) {
-      $build['#attached']['library'][] = 'site_alert/drupal.site_alert_ajax';
-      $build['#attached']['drupalSettings'] = [
-        'siteAlert' => [
-          'timeout' => $timeout,
-          'workaround_needed' => $workaround_needed,
+      $build['#attached'] = [
+        'library' => ['site_alert/drupal.site_alert'],
+        'drupalSettings' => [
+          'siteAlert' => [
+            'timeout' => $timeout,
+            'workaround_needed' => $workaround_needed,
+          ],
         ],
       ];
     }
@@ -167,7 +169,6 @@ class SiteAlertBlock extends BlockBase implements ContainerFactoryPluginInterfac
     }
 
     if (!empty($build)) {
-      $build['#attached']['library'][] = 'site_alert/drupal.site_alert';
       $build['#prefix'] = '<div class="site-alert site-alert-wrapper js-site-alert-wrapper" aria-live="polite">';
       $build['#suffix'] = '</div>';
     }

Let's avoid introducing any changes that are not strictly necessary. Not only increases this the risk on regressions but it also makes reviewing the patch more difficult and time consuming.

To me it seems these changes are out of scope for this issue:

  1. Introduction of a new library drupal.site_alert_ajax.
  2. Altering the scope of the existing library drupal.site_alert in a minor version.
  3. JS changes such as moving from let to const, changing the way siteAlert.load() is invoked, changing the classes on which the events are hooked, moving from drupalSettings to settings. All of these changes can be better handled in one or more separate issues.
  4. Let's avoid changing the structure of the site_alert render array because this potentially breaks existing sites that have theme overrides.
  5. Cleanup of the use statements in SiteAlertDeleteForm and SiteAlertAccessControlHander and cleanup of a typo of site_alert.services.yml are obviously good but out of scope of this issue. It makes this more time consuming to review.
  6. Let's not change any of the existing CSS, except the introduction of the sections that style the new .site-alert__dismiss and .site-alert__dismiss-icon classes.
pcate’s picture

StatusFileSize
new24.7 KB

Updated patch to work with the latest dev release. No other changes made.

alfattal’s picture

Patch in #41 and #51 cannot be applied. I'm getting this error message:
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2021-05-06/3156557-51.patch.

tjh’s picture

StatusFileSize
new13.5 KB

Attempted to clean up #51 to address some of the feedback from #50. Seems to work correctly on my local.

- Kept all JS in the same site alert library, so no libraries.yml updates. The second callback in loadAlert() still seems necessary (not sure if that's what #50 was directly referring to)
- Didn't update use statements/typos in files that weren't being changed already
- Kept original css
- Kept most new tests (a few removed for testing different libraries that no longer exist)

tjh’s picture

StatusFileSize
new15.34 KB

Missed a few files in the last patch... hopefully this one works 😅

anoopsingh92’s picture

Assigned: Unassigned » anoopsingh92

Hello,

I am trying to fix this issue. I will provide the Patch soon. Hope this will work.

Thanks

anoopsingh92’s picture

Hello @PCate,

I am trying to apply your patch #51 but it is not working. getting this issue.

Lenovo@LAPTOP-PDE747K8 MINGW64 /c/xampp/htdocs/drupal-9/web/modules/contrib/site_alert-3156557 (3156557-add-ability-to)
$ git apply -v 3156557-51.patch
Checking patch css/site_alert.css...
error: while searching for:
.site-alert {
  width: 100%;
  font-weight: bold;
}

.site-alert .text {
  padding: 10px 10px 10px 50px;
  margin: 0;
  font-size: 18px;
}

error: patch failed: css/site_alert.css:1
error: css/site_alert.css: patch does not apply
Checking patch js/site_alert.js...
error: while searching for:
 */

(function ($, Drupal, drupalSettings) {

  let callback;

  // Function to update alert text.
  let loadAlert = function (siteAlert) {
    // Object contains information about the currently loaded theme for
    // processing by our theme callback. Without it the default theme is always
    // assumed.
    let options = {
      ajax_page_state: drupalSettings.ajaxPageState
    };
    siteAlert.load(callback, options);

    if (drupalSettings.siteAlert.timeout > 0) {
      setTimeout(function () {

error: patch failed: js/site_alert.js:4
error: js/site_alert.js: patch does not apply
Checking patch js/site_alert_dismiss.js...
error: js/site_alert_dismiss.js: already exists in working directory
Checking patch site_alert.install...
error: site_alert.install: already exists in working directory
Checking patch site_alert.libraries.yml...
error: while searching for:
  css:
    theme:
      css/site_alert.css: {}
  js:
    js/site_alert.js: {}
  dependencies:
    - core/jquery
    - core/drupal
    - core/drupalSettings

error: patch failed: site_alert.libraries.yml:3
error: site_alert.libraries.yml: patch does not apply
Checking patch site_alert.services.yml...
error: while searching for:
    class: Drupal\site_alert\Cache\Context\ActiveSiteAlertsCacheContext
    arguments: ['@entity_type.manager', '@site_alert.get_alerts', '@private_key']
    tags:
      - { name: cache.context}

error: patch failed: site_alert.services.yml:9
error: site_alert.services.yml: patch does not apply
Checking patch src/Controller/SiteAlertController.php...
error: while searching for:
    $cache_metadata->setCacheMaxAge($this->entityTypeManager->getStorage('site_alert')->getCacheMaxAge());
    // Apply the cache context that varies by the currently active alerts.
    $cache_metadata->setCacheContexts(['active_site_alerts']);

    $build = [];
    foreach ($this->getAlerts->getActiveAlerts() as $alert) {
      $build[] = [
        '#theme' => 'site_alert',
        '#alert' => [
          'severity' => $alert->getSeverity(),
          'label' => $alert->getLabel(),
          'message' => [
            '#type' => 'markup',
            '#markup' => $alert->getMessage(),
          ],
        ],
        '#attached' => [
          'library' => ['site_alert/drupal.site_alert'],
        ],
      ];
      $cache_metadata->addCacheableDependency($alert);
    }
    $cache_metadata->applyTo($build);

    $response = new HtmlResponse();

error: patch failed: src/Controller/SiteAlertController.php:78
error: src/Controller/SiteAlertController.php: patch does not apply
Checking patch src/Entity/SiteAlert.php...
error: while searching for:

namespace Drupal\site_alert\Entity;

use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Datetime\DrupalDateTime;

/**
 * Implements SiteAlert class.

error: patch failed: src/Entity/SiteAlert.php:2
error: src/Entity/SiteAlert.php: patch does not apply
Checking patch src/Plugin/Block/SiteAlertBlock.php...
error: while searching for:
    $storage = $this->entityTypeManager->getStorage('site_alert');
    $scheduled_alerts_present = $storage->getCacheMaxAge() !== CacheBackendInterface::CACHE_PERMANENT;
    $workaround_needed = $scheduled_alerts_present && $this->moduleHandler->moduleExists('page_cache');

    $alerts = $this->getAlerts->getActiveAlerts();
    foreach ($alerts as $alert) {
      $metadata->addCacheableDependency($alert);
      // Avoid displaying the alert if we need to work around the core bug. This
      // prevents site alerts from briefly flashing in the page in case the bug

error: patch failed: src/Plugin/Block/SiteAlertBlock.php:113
error: src/Plugin/Block/SiteAlertBlock.php: patch does not apply
Checking patch src/SiteAlertAccessControlHandler.php...
error: while searching for:

namespace Drupal\site_alert;

use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;

/**
 * Implements SiteAlertAccessControlHandler class.

error: patch failed: src/SiteAlertAccessControlHandler.php:2
error: src/SiteAlertAccessControlHandler.php: patch does not apply
Checking patch templates/site-alert.html.twig...
error: while searching for:
<div class="severity-{{ alert.severity }}">
  <div class="text">
    {{ alert.message }}
  </div>
</div>

error: patch failed: templates/site-alert.html.twig:1
error: templates/site-alert.html.twig: patch does not apply
Checking patch tests/src/Functional/SiteAlertUiTest.php...
error: while searching for:
    $this->fillField('Active', '1');
    $this->fillField('Severity', 'high');
    $this->fillField('Message', 'Test alert.');
    $this->pressButton('Save');
    $assert->statusCodeEquals(200);


error: patch failed: tests/src/Functional/SiteAlertUiTest.php:63
error: tests/src/Functional/SiteAlertUiTest.php: patch does not apply
Checking patch tests/src/FunctionalJavascript/SiteAlertCacheWorkaroundTest.php...
error: while searching for:
    $this->drupalGet('<front>');
    $this->assertSiteAlertNotVisible('Scheduled alert');

    // Since the workaround is in effect, the JavaScript code that is
    // responsible for refreshing the alerts should be loaded in the page.
    $this->assertJavaScriptPresent();

error: patch failed: tests/src/FunctionalJavascript/SiteAlertCacheWorkaroundTest.php:56
error: tests/src/FunctionalJavascript/SiteAlertCacheWorkaroundTest.php: patch does not apply
Checking patch tests/src/FunctionalJavascript/SiteAlertDismissTest.php...
error: tests/src/FunctionalJavascript/SiteAlertDismissTest.php: already exists in working directory
Checking patch tests/src/FunctionalJavascript/SiteAlertWebDriverTestBase.php...
error: while searching for:
  }

  /**
   * Asserts that the JavaScript code to refresh the alerts is present.
   */
  protected function assertJavaScriptNotPresent() {
    $this->assertElementNotPresent('script[src*="site_alert.js"]');
  }

}

error: patch failed: tests/src/FunctionalJavascript/SiteAlertWebDriverTestBase.php:132
error: tests/src/FunctionalJavascript/SiteAlertWebDriverTestBase.php: patch does not apply

anoopsingh92’s picture

Hello @tjh,

Your patch is also not working for me. I am getting this when I apply your patch.

$ git apply -v 3156557-53.patch
Checking patch css/site_alert.css...
error: while searching for:
  background-position: 1% 50%;
  margin-bottom: 1.5em;
}

error: patch failed: css/site_alert.css:45
error: css/site_alert.css: patch does not apply
Checking patch js/site_alert.js...
error: while searching for:
    let options = {
      ajax_page_state: drupalSettings.ajaxPageState
    };
    siteAlert.load(callback, options);

    if (drupalSettings.siteAlert.timeout > 0) {
      setTimeout(function () {

error: patch failed: js/site_alert.js:15
error: js/site_alert.js: patch does not apply
Checking patch src/Controller/SiteAlertController.php...
error: while searching for:
      $build[] = [
        '#theme' => 'site_alert',
        '#alert' => [
          'severity' => $alert->getSeverity(),
          'label' => $alert->getLabel(),
          'message' => [
            '#type' => 'markup',
            '#markup' => $alert->getMessage(),
          ],
        ],
        '#attached' => [
          'library' => ['site_alert/drupal.site_alert'],

error: patch failed: src/Controller/SiteAlertController.php:84
error: src/Controller/SiteAlertController.php: patch does not apply
Checking patch src/Entity/SiteAlert.php...
Hunk #1 succeeded at 79 (offset -9 lines).
error: while searching for:
      ])
      ->setRequired(TRUE);

    $fields['scheduling'] = BaseFieldDefinition::create('daterange')
      ->setLabel(t('Scheduling'))
      ->setDisplayOptions('form', [
        'type' => 'daterange_default',
        'weight' => 4,
      ]);

    return $fields;

error: patch failed: src/Entity/SiteAlert.php:186
error: src/Entity/SiteAlert.php: patch does not apply
Checking patch src/Plugin/Block/SiteAlertBlock.php...
error: while searching for:
      $build[] = [
        '#theme' => 'site_alert',
        '#alert' => [
          'severity' => $alert->getSeverity(),
          'label' => $alert->getLabel(),
          'message' => [
            '#type' => 'markup',
            '#markup' => $alert->getMessage(),
          ],
        ],
      ];
    }

error: patch failed: src/Plugin/Block/SiteAlertBlock.php:126
error: src/Plugin/Block/SiteAlertBlock.php: patch does not apply
Checking patch templates/site-alert.html.twig...
error: while searching for:
<div class="severity-{{ alert.severity }}">
  <div class="text">
    {{ alert.message }}
  </div>
</div>

error: patch failed: templates/site-alert.html.twig:1
error: templates/site-alert.html.twig: patch does not apply
Checking patch tests/src/Functional/SiteAlertUiTest.php...
error: while searching for:
    $this->fillField('Active', '1');
    $this->fillField('Severity', 'high');
    $this->fillField('Message', 'Test alert.');
    $this->pressButton('Save');
    $assert->statusCodeEquals(200);


error: patch failed: tests/src/Functional/SiteAlertUiTest.php:63
error: tests/src/Functional/SiteAlertUiTest.php: patch does not apply
Checking patch tests/src/FunctionalJavascript/SiteAlertCacheWorkaroundTest.php...
error: while searching for:
    $this->drupalGet('<front>');
    $this->assertSiteAlertNotVisible('Scheduled alert');

    // Since the workaround is in effect, the JavaScript code that is
    // responsible for refreshing the alerts should be loaded in the page.
    $this->assertJavaScriptPresent();

error: patch failed: tests/src/FunctionalJavascript/SiteAlertCacheWorkaroundTest.php:56
error: tests/src/FunctionalJavascript/SiteAlertCacheWorkaroundTest.php: patch does not apply
Checking patch tests/src/FunctionalJavascript/SiteAlertDismissTest.php...
error: while searching for:

error: patch failed: tests/src/FunctionalJavascript/SiteAlertDismissTest.php:0
error: tests/src/FunctionalJavascript/SiteAlertDismissTest.php: patch does not apply
Checking patch tests/src/FunctionalJavascript/SiteAlertWebDriverTestBase.php...
error: while searching for:
  }

  /**
   * Asserts that the JavaScript code to refresh the alerts is present.
   */
  protected function assertJavaScriptNotPresent() {
    $this->assertElementNotPresent('script[src*="site_alert.js"]');
  }

}

error: patch failed: tests/src/FunctionalJavascript/SiteAlertWebDriverTestBase.php:132
error: tests/src/FunctionalJavascript/SiteAlertWebDriverTestBase.php: patch does not apply

Thanks

anoopsingh92’s picture

Hello,

I have fixed most of the issues. But these issues are still pending.

FILE: C:\xampp\htdocs\drupal-9\web\modules\contrib\site_alert-3156557\site_alert.module
---------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
---------------------------------------------------------------------------------------
 22 | WARNING | Global constants should not be used, move it to a class or interface
---------------------------------------------------------------------------------------


FILE: C:\xampp\htdocs\drupal-9\web\modules\contrib\site_alert-3156557\src\Plugin\Block\SiteAlertBlock.php
---------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------
 71 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
---------------------------------------------------------------------------------------------------------

Time: 590ms; Memory: 10MB

I am uploading the latest patch. Hope this will work finely.

Thanks

anoopsingh92’s picture

Hello,

I have fixed dependency injection also Now only this issue is pending.

Lenovo@LAPTOP-PDE747K8 MINGW64 /c/xampp/htdocs/drupal-9/web/modules/contrib ((4106d4a...))
$ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig site_alert-3156557/

FILE: C:\xampp\htdocs\drupal-9\web\modules\contrib\site_alert-3156557\site_alert.module
---------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
---------------------------------------------------------------------------------------
 22 | WARNING | Global constants should not be used, move it to a class or interface
---------------------------------------------------------------------------------------

Time: 534ms; Memory: 10MB

Thanks

anoopsingh92’s picture

StatusFileSize
new3.64 KB

Hello,

I have uploaded my patch. Please test and review. I hope this will work.

Thanks

anoopsingh92’s picture

Assigned: anoopsingh92 » Unassigned
Status: Needs work » Needs review
igork96’s picture

Version: 8.x-1.1 » 8.x-1.x-dev

I tested the patch from #51 against the dev branch and can confirm that it is working as described, for logged and anonymous users. After you import the patch you need to run drush updb in order field_dismissible to be created on-site alerts.

nadim hossain’s picture

StatusFileSize
new17.14 KB

Rerolled the patch to match with the new release 8.x-1.3

alfattal’s picture

Patch in #63 failed to apply on the new release 8.x-1.3.

$ composer install
Gathering patches for root package.
Removing package drupal/site_alert so that it can be re-installed and re-patched.
  - Removing drupal/site_alert (1.3.0)
Deleting docroot/modules/contrib/site_alert - deleted
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.
Package operations: 1 install, 0 updates, 0 removals
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
  - Installing drupal/site_alert (1.3.0): Extracting archive
  - Applying patches for drupal/site_alert
    https://www.drupal.org/files/issues/2020-06-25/3154942-2.patch (3154942-2: Separate AJAX target from wrapper)
    https://www.drupal.org/files/issues/2020-08-17/3151256-3.patch (3151256-3: Allow the ability to add multiple blocks)
    https://www.drupal.org/files/issues/2023-02-15/3156557-63.patch (3156557-63: Add ability to dismiss alert)
   Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2023-02-15/3156557-63.patch

In Patches.php line 326:
                                                                                                                                  
  Cannot apply patch 3156557-63: Add ability to dismiss alert (https://www.drupal.org/files/issues/2023-02-15/3156557-63.patch)!  
                                                                                                                                  

install [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--dry-run] [--dev] [--no-suggest] [--no-dev] [--no-autoloader] [--no-progress] [--no-install] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [<packages>...]
alfattal’s picture

Status: Needs review » Needs work
rpayanm’s picture

Status: Needs work » Needs review

The patch applies well on the last release, be aware you are using several patches on that module, there might be a conflict there.

nadim hossain’s picture

StatusFileSize
new24.71 KB

Patch #63 was missing some new files that got missed during the re roll. I have updated the patch. Please try using this and see if it works. Also keep in in mind as rpayanm mentioned, using other patches might create conflicts as well.

nadim hossain’s picture

StatusFileSize
new36.08 KB
new12.28 KB

I have done some testing as well just to check the patch I submitted works as expected and patch #67 is working for me. Please see the screenshots below -

markie made their first commit to this issue’s fork.

markie’s picture

Status: Needs review » Reviewed & tested by the community

Able to patch the current MR which was created with #67. Tested and successfully able to dismiss an alert. I do like how this splits the style away from the functionality.