Validate that block config includes at least one newsletter

Created on 14 February 2024, 4 months ago
Updated 11 March 2024, 3 months ago

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

  1. On https://simplytest.me/ install the module '4.0.0-rc1' on Drupal '10.2.3'
  2. Login as 'admin' (user and ps)
  3. Add a block for 'Simplenews subscription', leave all default fields and save.
  4. Go to homepage and check the block in the region you added for the theme.
  5. 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.
  6. 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.

📌 Task
Status

Fixed

Version

4.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024