Problem/Motivation
We'd really like to have one-click Mailchimp integration in Drupal CMS.
Mailchimp's authentication with OAuth is already really slick, and all we need is some kind of recipe that expedites the initial set-up process after you, as the site owner, have successfully authenticated with Mailchimp.
The set-up process, such as it is, includes:
- Creating some signup entities, based on the lists you have set up at the Mailchimp end
- Creating some signup forms, based on those signup entities
How can we translate this to a recipe? Why, with Drupal CMS's favorite tool: ECA, which is the best tool out there for implementing complex workflows without code.
Let's create an ECA model which:
- Springs into action when authentication has been finished. We can detect this because the
access_tokenconfig setting will change. At that point... - ...the model should invoke a custom action (supplied by a new Mailchimp submodule) which queries the Mailchimp API for all currently defined lists.
- The model should take the output of that action (a list of lists), and for each one, create a signup entity.
The model should also take action whenever a signup entity is created -- that action should be creating a signup form for that signup entity.
We'll package that ECA model into a new recipe (name TBD). The recipe will expose a "Log in" task to Project Browser (see https://project.pages.drupalcode.org/distributions_recipes/integrations.... for info) which, when clicked, sends you to the OAuth authentication form. The recipe will also, as a matter of course, unconditionally opt the site into using OAuth to authenticate with Mailchimp.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | eca.eca_.mailchimp_signup_forms_2.yml | 7.24 KB | gcb |
| #7 | eca.eca_.mailchimp_signup_forms.yml | 6.44 KB | gcb |
| #5 | mc-recipe.zip | 2.86 KB | jurgenhaas |
Issue fork mailchimp-3538595
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
jurgenhaasI'm getting started on this.
Comment #4
jurgenhaasThe action plugin appeared to be straightforward, already available in the MR above. I'm now building the ECA model that creates the entities and blocks.
Comment #5
jurgenhaasThis is now ready for review. Here are the steps to take:
The ECA model currently responds to a changed
api_timeoutconfig value. This can later be changed when oauth is being sorted out.This model reads the lists from the MC account and then creates (or updates) basic signup entities and blocks. There are still some details that need to be sorted, especially the merge field information that's in the signup entity. I'm not sure where they're coming from or how they get generated.
If you want to review or modify the ECA model, you need to install the bpmn_io module and then go to
/admin/config/workflow/ecawhere you can view or edit the model.Comment #6
gcbComment #7
gcbExciting stuff! Some thoughts here
I've attempted to add an ECA Action that collects our mergevars. You can see it here.
Using that, and the config file attached here, I thought I could initialize those in the configurations. Any feedback on those elements would be welcome, I'm not having great success getting a good configuration created.
Comment #8
jurgenhaasAmazing, well done.
There are 3 problems I found:
signup_form_[item:id]but the config name remained unchanged asmailchimp_signup.mailchimp_signup.[item:id]. That causes a problem that the config name doesn't match the entity ID and that makes it invalid. Please keep that consistent.mergevar, but that needs to bemergevars.mailchimp_get_mergevarsin your new action plugin before the signup entity has been created. That seems to be causing an issue.Hope this helps you going the next steps. Please let me know if I should have another look when you addressed those issues.
Comment #9
gcbOk @jurgenhaas -- here's a PR with an improved plugin, the foundation of an actual api service, and here's a working version of our ECA setup that uses it (renamed awkwardly by drupal.org security -- I see why you used a zipfile before)
Comment #10
jurgenhaas@gcb I guess there must be some updated or enhanced PHP code but I can't find that. Could you commit that to the existing MR?
Comment #11
gcbYeah it would help if I linked to the MR :/
https://git.drupalcode.org/project/mailchimp/-/merge_requests/111
Comment #12
jurgenhaasOK, thanks @gcb. I've merged that MR into MR!110 which is the attached MR to this issue, that's probably easier to handle?
The current code looks really good and it works as expected.
In Slack you mentioned that you're now looking for a new event: "Now to trigger the authentication when the recipe is enabled…". However, what's already in the ECA model is an event that triggers the thing when the API key gets updated. This could be adjusted to oauth settings when you're using them instead. I don't think that you need yet another event which is recipe related, because that would be dispatched too early, probably. You want to run when authentication is being configured.
Comment #13
gcbOh, there sure is! I didn't even notice the second trigger. So we would just remove the Config change trigger from our existing recipe.
Comment #15
fjgarlin commentedfinal readonly class ApiServiceThat is a PHP8.2 only feature and it breaks Drupal sites running on PHP8.1. The PHP constraint could be indicated in composer.json to avoid this, or removing the word "readonly", which is preferred and keeps PHP8.1 compatibility.
Comment #17
fjgarlin commentedThe pipelines are happy with the change and it now tests D10 (with PHP8.1).
The issue we were having, in latest stable D10 and PHP8.1 was:
Comment #18
drummComment #19
xenophyle commented