Problem/Motivation
When adding the module block, if you don't select a newsletter under 'Visible Newsletters' on the block config page, it always shows the message "You are already subscribed" regardless of the actual status. This includes to admin and anonymous users. The "Subscribe" button is disabled and the "Manage existing" link shows always. This makes the block useless and confusing.
No mention of having to select a newsletter on the block config page and no related warning is shown on saving the block.
Steps to reproduce
- On https://simplytest.me/ install the module '4.0.0-rc1' on Drupal '10.2.3'
- Login as 'admin' (user and ps)
- Add a block for 'Simplenews subscription', leave all default fields and save.
- Go to homepage and check the block in the region you added for the theme.
- As a logged in admin you see the above message. Click on the 'Manage existing' and you'd see the 'Default newsletter' unchecked. Try check it > save and then uncheck and save. Check the block again, no change.
- Logout and check the block again and you shall see the same as anonymous.
Please see attached screenshot.
Now go back to the block admin and check 'Default newsletter' under ' Visible Newsletters ' . Save and check again on homepage. No you see the subscription message showing correctly and respecting the subscription status.
Proposed solution
Add a blockValidate() function that sets a form error if both newsletters and default_newsletters are empty. Either one can be blank, but not both.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | simplenews.validate-block.3421481-18.patch | 896 bytes | adamps |
| #2 | simplenews-issue-cause.png | 43.54 KB | cestmoi |
| simplenews-issue.png | 83.74 KB | cestmoi |
Issue fork simplenews-3421481
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
Comment #2
cestmoi commentedIt turned out that I had to select at least one newsletter under 'Visible Newsletters' on the block config page. Now everything seems to be functioning as expected. I hope this helps someone who comes across such an issue.
Perhaps it's better if the block wouldn't save without selecting a newsletter or at least a warning message is shown on the block config page.
Comment #3
cestmoi commentedAdjusted the issue text to show what really needs to be done.
Comment #5
himanshu_jhaloya commentedComment #6
himanshu_jhaloya commentedHi, I followed the Steps to reproduce the issue I found that for anonymous it also shows that You are already subscribed to resolve this issue I have Added a message on the block admin page to select a newsletter and ' Visible Newsletters ' a required field.
please review the patch.
Comment #7
himanshu_jhaloya commentedComment #8
ressaThanks @himanshu_jhaloya! Manually attaching patches is being phased out, so perhaps you can create a patch and Merge Request with the Gitlab integration?
DrupalCI and all patch testing will be turned off on July 1, 2024
Comment #10
himanshu_jhaloya commentedCreated the Mr for the same please Review
Comment #11
ressaNice, thanks @himanshu_jhaloya I really appreciate it.
Comment #12
cestmoi commentedThank you @himanshu_jhaloya but this patch while addressed the required select on the block config page, it's causing the below error on trying to access any page that has the block:
Comment #13
cestmoi commentedComment #14
adamps commentedThe requirement is that you must set either
newslettersordefault_newsletters. Either one can be blank, but not both.Comment #18
adamps commentedComment #19
adamps commented