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.

Issue fork simplenews-3421481

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

cestmoi created an issue. See original summary.

cestmoi’s picture

StatusFileSize
new43.54 KB

It 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.

cestmoi’s picture

Title: "You are already subscribed" shows to everyone including anonymous, and "subscribe" button disabled for all » "You are already subscribed" shows to everyone including anonymous, and "subscribe" button disabled for all if no newsletter is selected on the block config
Category: Bug report » Task
Issue summary: View changes

Adjusted the issue text to show what really needs to be done.

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

himanshu_jhaloya’s picture

Assigned: Unassigned » himanshu_jhaloya
himanshu_jhaloya’s picture

StatusFileSize
new2.48 KB

Hi, 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.

himanshu_jhaloya’s picture

Assigned: himanshu_jhaloya » Unassigned
Status: Active » Needs review
ressa’s picture

Status: Needs review » Needs work

Thanks @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

himanshu_jhaloya’s picture

Status: Needs work » Needs review

Created the Mr for the same please Review

ressa’s picture

Nice, thanks @himanshu_jhaloya I really appreciate it.

cestmoi’s picture

Thank 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:

Error: Call to undefined method
Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsButtonsWidget::setAvailableNewsletterIds() in Drupal\simplenews\Form\SubscriptionsBlockForm->form() (line 131 of ..... \web\modules\contrib\simplenews\src\Form\SubscriptionsBlockForm.php).
cestmoi’s picture

Status: Needs review » Needs work
adamps’s picture

Title: "You are already subscribed" shows to everyone including anonymous, and "subscribe" button disabled for all if no newsletter is selected on the block config » Validate that block config includes at least one newsletter
Priority: Major » Normal
Issue summary: View changes

The requirement is that you must set either newsletters or default_newsletters. Either one can be blank, but not both.

AdamPS changed the visibility of the branch 3421481-you-are-already to hidden.

AdamPS changed the visibility of the branch newsletter to hidden.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new896 bytes
adamps’s picture

Status: Needs review » Fixed

  • AdamPS committed 0b24ba93 on 4.x
    Issue #3421481 by himanshu_jhaloya, AdamPS: Validate that block config...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.