Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
To keep my site layout simple i want to hide the subscription block in case a user is already subscribed to my mailchimp newsletter.
what is the best practice to do that? is there an API call to achieve it or do i need to dig it out of the DB?
Comments
Comment #1
seanberto CreditAttribution: seanberto commentedHi Bara,
I'll chat with Lev about this. Just to clarify, how would the user unsubscribe then? Via the user profile screen?
-s
Comment #2
levelos CreditAttribution: levelos commentedThere's an API call in the module, _mailchimp_is_subscribed(). Note that this pings MailChimp, so isn't particularly fast.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedping every time would be a bit intense. yes the user needs to go to his profile page or unsubscribe via newsletter link.
Comment #4
rickmanelius CreditAttribution: rickmanelius commentedHey Everyone,
I'm reopening this because merely having an API call is not front-end user solution. I actually had a client request this, so it's still a valid feature request.
Goal: A block visibility setting that could turn off this block if a user is already subscribed.
Questions 1: User profile updates
- Yes. I'd still like to keep the full subscription options in the user page (see comment #1). The block is more for getting new users to opt in. After that, seeing the block can get annoying. After all, how many times do you really need to update your preferences?
- Additionally, since this information is pulled from the mailchimp API and not stored in the local db, a person unsubscribing from the newsletter email itself would have their preferences respected.
Question 2: What about performance?
- Again, if the block already requires pinging mailchimp for a person's current subscription settings, it'll be no more difficult at hook_block to simply return null and move on.
Implementation would essentially be a system setting attached to the mailchimp block itself that would be a binary flag to do the above.
If it would get committed to the module, I'll gladly provide a patch.
Comment #5
levelos CreditAttribution: levelos commentedSorry rickman, but I don't feel an additional setting to hide blocks for given lists if a user is already is a broad enough use case to warrant inclusion in the module. There are many approaches you could take to solve this problem in your own code.
Comment #6
rickmanelius CreditAttribution: rickmanelius commentedI would disagree simply on the basis that one could see putting a 'subscribe to learn more' block on any content page in order to get the highest subscription rate... and then this very same block being repetitive to those already subscribed!
But, I'm not here to argue. I'll simply hack the mailchimp module block and do it that way.
Comment #7
seanberto CreditAttribution: seanberto commentedHi Rickman,
Lev and I didn't mean to imply that your use case isn't valid, only that the settings form for the 6.x branch is already pretty cluttered with options and that this use case pry doesn't warrant adding that complexity to all users. Moreover, we are focused on the 7.x-2x branch of the module for new features, so it isn't something that we are interested in adding.
I think that it would be interesting for you to post your solution to this ticket for others that might want to handle this. I'm pretty sure that you could handle this with block visibility overrides, rather than hacking the module - which hopefully presents a more sustainable solution.
Thanks for the discussion and sharing your ideas/solutions!
-sean
Comment #8
patrickharris CreditAttribution: patrickharris commentedH'mm - it's very unintuitive to have a block ask you to subscribe, when you already are. The only way of using the block as it currently is, seems to be to use it as a "subscribe any email to our Newsletter" block.
Comment #9
rickmanelius CreditAttribution: rickmanelius commentedHi Seanberto,
Will definitely post my changes compared to the drupal 7 branch. And no offense taken! I know you guys have a ton going on. I just wanted to plead my case :)
I'll be working on this clients work this thursday, so I'll probably get a patch together by the weekend.
Comment #10
ryank76 CreditAttribution: ryank76 commentedWas there any progress? I agree with #8, it's weird to be shown a block if you're already subscribed.
A way to change the text if the user is subscribed would be an option.
Comment #11
ryank76 CreditAttribution: ryank76 commentedWhat about a block setting for
So it shows the block if the 'user is not subscribed' code returns TRUE. Is that possible? (Not a developer)
Comment #12
pierrot CreditAttribution: pierrot commentedI wrote this in block setting to avoid the block to be shown for subscribed users, except on their user profile :
Hope this helps