I am thinking about implementing the submissions email system through Rules instead of handling it directly via this module. I think users are going to want a more complex email system and Rules will allow this.

I would appreciate any feedback on this idea.

Here is my proposed solution.

  1. Create 2 default "Rules Components"(not Reaction Rules. "Email Submitter on Submission" and "Notitfy Others on submission"
  2. Tag these rules with "Entityform Submission"
  3. On the EntityForm Type Edit page I would let the admin choose the Rules to trigger on submission. This would be a list of Rules Components tagged with "Entityform Submission"(this would allow the admin to create new rules)
  4. In hook_entity_save I would check which Rule Components should be trigger and run them programmitcally.

This would provide that ability to:

  • Let the Admin create new Rule Components that would be selectable by users who are editing or creating entityform types.
  • Let users creating Entityforms select which Rules should be triggered for each form without having to have access to the Rules admin interface(or even have it turned on).
  • Provide much more flexibility in controlling when emails should be sent. Could be affected by: user role, field values of submission
  • Provide flexibility on who emails are sent to. For example:
    • Users could select Entityforms they would like to monitor by using a entityreference field of entityforms in their user profile.
    • Send emails to all users of a certain role
    • Send an email to users that are selected from and entityreference field in the entityform submission.
    • Complex selection of users from a View with the contextual filters supplied by field values of the submission.

Though I would not be using Reaction Rules for this the site builder could also create Reaction Rules to send emails.
This change would require that the Rules module be required.

Comments

tedbow’s picture

Status: Active » Needs review

I have started a scratch branch for this change: http://drupalcode.org/project/entityform.git/shortlog/refs/heads/rule_no...

I have done most of the changes above.

tedbow’s picture

I have made an update the branch linked to above.

This changes use a token in the Email Rule to send the form field submission information to the user.
The token requires a new module I made called: Entity To Text

This uses the same logic I use to have in this module for turning the Entityform into text but works with any fieldable entity.

tedbow’s picture

Question: I am thinking about not making Rules dependency for this module. I would display a notice in place if the site didn't have Rules enabled. Something like:

Enable the Rules module to use notifications for this module.

My thinking is that if a site doesn't want to use notifications why should they have to enable Rules.

The reason to require Rules would be that is such a useful module and notifications are such a basic requirement why not make it a requirement.

Any thoughts?

tedbow’s picture

I updated the branch with an update_hook_n function that sets the correct Rules settings. This makes Rules required.

tedbow’s picture

I merged this branch into the main dev branch.

I am going to leave this as "needs review" because I still want feedback on it.

You will need to run database updates for this to work and have Rules.

Kristen Pol’s picture

I upgraded to alpha6, installed/enabled Rules, and ran update.php and no email was sent for my entityform. I went into the entityform settings and found that all the notification settings were empty. So, I filled them in and tried again, but still didn't get an email. I tried these tests as anonymous as that was the issue we were having before. I'll try them as a logged-in user now.

Kristen Pol’s picture

I used an admin account and still no email is sent. Is there some Rules configuration that needs to happen?

tedbow’s picture

@Kristen Pol
Do you see the setting "Submission Rules" under "Notification Settings"?
There should be 2 default Rules that you can select here.

  1. Email Entityform Submitter: should email the user who submitted the form
  2. Email Entityform Admin(should rename): should email the "Notify Emails" settings of the form.

If you select them them they should email send an email.

Do you see these setting above?

tedbow’s picture

I am starting to write documentation on this: http://drupal.org/node/1679794

Help out if you can.

Kristen Pol’s picture

Sorry, I should have mentioned that that Rules section was completely *empty*. :/

[Update] Not really... see comments below.

Kristen Pol’s picture

I updated the documentation with some minor formatting/typo fixes for now. One note is that I think "a email" should be "an email" in the rules names. I didn't change those, though, since those are probably referencing what's in your code.

Kristen Pol’s picture

The rules are showing up now that I enabled the Rules UI module. I've updated the documentation and I'll test the emails now.

Kristen Pol’s picture

Note that I went to the wrong place initially (went to Configuration » Content authoring » Entityform settings) and that's why I didn't see the old email message or email addresses. They were there when I went to the correct place! And, the two rules were preselected for me (after the Rules UI module was enabled).

I tested my Entityform with both a logged-in user and as anonymous and I got emails sent to the "Notification emails" email address. But, now I'm wondering how to get it to send it to the submitter. Does it check all the email address fields on the form? Is this configured somewhere? I'm not seeing it. It's probably documented somewhere so I'll look in a bit.

Thanks!

Kristen Pol’s picture

I will copy the rule component to my own custom one and then update it to use the email field I have specified in the form. I assume it should work fine.

Kristen Pol’s picture

Ok, I got it to work and updated the documentation with the steps. Note that it would be super handy for users who are not familiar with Rules to have an easy way to preselect the email field from within the Entityform UI and have it use that field if the user is not logged in.

Kristen Pol’s picture

Status: Needs review » Reviewed & tested by the community

Since this is working as expected, I'm marking RTBC.

mrfelton’s picture

Status: Reviewed & tested by the community » Needs work

Works well here. Though, see #1680682: More flexible rules based notification system for some suggestions for possible improvements.

mrfelton’s picture

Status: Needs work » Reviewed & tested by the community

Oops, didn't rean to reset the status,=.

tedbow’s picture

Status: Reviewed & tested by the community » Fixed

This has been committed. Related work here #1680682: More flexible rules based notification system

Status: Fixed » Closed (fixed)

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