Reviewed & tested by the community
Project:
Site Alert
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
2 Jul 2020 at 21:40 UTC
Updated:
8 Jun 2025 at 16:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
nejcramsak commentedHi, i created a patch for this. Needs review.
Comment #4
ntaylor1994 commentedWhen 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.
Comment #5
pavnish commented@ntaylor1994 i have check this is working fine for me for reference please find the screenshot.
Comment #6
pavnish commented@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
Comment #8
pavnish commented@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.
Comment #9
nejcramsak commentedHi @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.
Comment #10
nejcramsak commentedI 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.
Comment #11
pcate commentedThere 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:
with the icon CSS being moved to the
.dismiss__iconelement.Comment #12
nejcramsak commentedHi, 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.
Comment #13
pcate commented@nejcramsak the JavaScript doesn't load if the block Timeout setting is set to 0. Appears to be from this code:
in the
SiteAlertBlock.phpfile.Comment #14
pcate commentedComment #15
pcate commentedRe-rolled patch #12 to work with latest dev version. No other changes.
Comment #16
pcate commentedAfter more testing I found some additional issues.
I needed this for a client, so I refactored with the following changes.
Twig template
JavaScript
Block
CSS
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.
Comment #17
pcate commentedComment #19
pcate commentedFixed issue with scheduled alerts not rendering with ID,.
Comment #20
pcate commentedComment #22
pcate commentedUpdated 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.
Comment #23
pcate commentedComment #24
pcate commentedMinor update to patch to fix some PHP CS warnings found in tests.
Comment #25
pcate commentedFound an issue where some JS wasn't being loaded correctly if the timeout was set to 0. Will work on a fix.
Comment #26
pcate commentedComment #27
pcate commentedComment #28
pcate commentedComment #29
pcate commentedComment #30
pcate commentedPatch #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.
Comment #31
pcate commentedComment #32
pcate commentedComment #33
nejcramsak commentedHi, 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.
Comment #34
pcate commentedI think I found the missing CSS issue. I also went ahead and added a JavaScript test.
Comment #35
pcate commentedComment #36
nejcramsak commentedI tested the patch and it works. The CSS issue is now fixed and the dismissing worked great so setting this as RTBC.
Comment #37
ntaylor1994 commentedIm not seeing the dismiss button. Also, when i check dismissable and save then go back and check, the checkbox is not marked anymore.
Comment #38
pcate commented@ntaylor1994 After applying the patch did you run a database update and clear all caches?
Comment #39
pfrenssenWith this patch I am seeing icons pop up where there were none before. I think it is this change causing it:
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.
Comment #40
ntaylor1994 commentedI 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
Comment #41
pcate commentedUpdated patch to revert from using
background-colorto the originalbackgroundComment #42
pcate commented@pfrenssen let me know if #41 fixes the icons showing where they weren't before.
Comment #43
pcate commentedI 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......
Comment #44
jasonluttrell#41 works for me, though I cannot say anything about icons appearing in the wrong place. It seems RTBC.
Comment #45
ntaylor1994 commentedWhen do you think this can go live?
Comment #46
pcate commented@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?
Comment #47
pfrenssenThanks for the callout, I agree that it would be good moment to go through the RTBC queue.
Comment #48
pfrenssenI'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:
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.
Comment #49
pfrenssenComment #50
pfrenssenThe 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_alertlibrary into a new library calledsite_alert_ajaxbut this is causing the regression. If I revert this change by applying the following patch the alerts appear normal again: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:
drupal.site_alert_ajax.drupal.site_alertin a minor version.lettoconst, changing the waysiteAlert.load()is invoked, changing the classes on which the events are hooked, moving fromdrupalSettingstosettings. All of these changes can be better handled in one or more separate issues.site_alertrender array because this potentially breaks existing sites that have theme overrides.SiteAlertDeleteFormandSiteAlertAccessControlHanderand cleanup of a typo ofsite_alert.services.ymlare obviously good but out of scope of this issue. It makes this more time consuming to review..site-alert__dismissand.site-alert__dismiss-iconclasses.Comment #51
pcate commentedUpdated patch to work with the latest dev release. No other changes made.
Comment #52
alfattal commentedPatch 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.
Comment #53
tjh commentedAttempted 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)
Comment #54
tjh commentedMissed a few files in the last patch... hopefully this one works 😅
Comment #55
anoopsingh92Hello,
I am trying to fix this issue. I will provide the Patch soon. Hope this will work.
Thanks
Comment #56
anoopsingh92Hello @PCate,
I am trying to apply your patch #51 but it is not working. getting this issue.
Comment #57
anoopsingh92Hello @tjh,
Your patch is also not working for me. I am getting this when I apply your patch.
Thanks
Comment #58
anoopsingh92Hello,
I have fixed most of the issues. But these issues are still pending.
I am uploading the latest patch. Hope this will work finely.
Thanks
Comment #59
anoopsingh92Hello,
I have fixed dependency injection also Now only this issue is pending.
Thanks
Comment #60
anoopsingh92Hello,
I have uploaded my patch. Please test and review. I hope this will work.
Thanks
Comment #61
anoopsingh92Comment #62
igork96 commentedI 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 updbin orderfield_dismissibleto be created on-site alerts.Comment #63
nadim hossain commentedRerolled the patch to match with the new release 8.x-1.3
Comment #64
alfattal commentedPatch in #63 failed to apply on the new release 8.x-1.3.
Comment #65
alfattal commentedComment #66
rpayanmThe patch applies well on the last release, be aware you are using several patches on that module, there might be a conflict there.
Comment #67
nadim hossain commentedPatch #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.
Comment #68
nadim hossain commentedI 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 -
Comment #71
markie commentedAble 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.