The contact_storage module supplies an 'Options email' field which allows you to base the recipient of the contact module's e-mail on a chosen value.

Please see the attached patch which allows you to select an 'Options email' field as a valid recipient field for contact_emails mails.

Comments

Ruuds created an issue. See original summary.

scott_euser’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks for adding this option! Generally looks fine but just a couple things and one question

  1. +++ b/src/Entity/ContactEmail.php
    @@ -506,13 +506,23 @@ class ContactEmail extends ContentEntityBase implements ContactEmailInterface {
    +      $allowedValues = $definition->getSetting('allowed_values');
    

    Coding standards should be $allowed_values = ... as its not a property of the class

  2. +++ b/src/Entity/ContactEmail.php
    @@ -506,13 +506,23 @@ class ContactEmail extends ContentEntityBase implements ContactEmailInterface {
    +              $results += explode(',', $allowedValues[$email['value']]['emails']);
    

    Is it possible that this is empty and causes a notice?

  3. Needs test coverage added along with the new option, perhaps could go here in the ContactEmailsRecipientTest
ruuds’s picture

StatusFileSize
new6.02 KB
new4.61 KB

@scott_euser thank you for your feedback.

1. Is fixed in the attached patch
2. $allowedValues[$email['value']]['emails'] will only be empty or not set when an invalid value is posted to the form, which will not happen in normal situations
3. I've added a test in the attached patch.

ruuds’s picture

Status: Needs work » Needs review
matt b’s picture

Status: Needs review » Needs work
StatusFileSize
new2.18 KB

I need this as I use Options email. I could not get the patch in #3 to apply to either 8.x-1.x-dev or 8.x-1.20 (no surprise - it's two years old!)

I got the following error on 8.x-1.20

error: patch failed: src/ContactEmailsTestBase.php:2
error: src/ContactEmailsTestBase.php: patch does not apply
error: patch failed: src/Tests/ContactEmailsRecipientTest.php:84
error: src/Tests/ContactEmailsRecipientTest.php: patch does not apply

So I removed the ContactEmailsTestBase and ContactEmailsRecipientTest elements from the patch and it then applied. I've tested it and it all works fine. I'd have been happy to move this to RTBC if I hadn't hacked the patch.

I've attached the 'hacked' patch file, but you really need to re-instate the test stuff I guess?

matt b’s picture

Could whoever maintains this module move this forward please?

matt b’s picture

Has this been applied?

ruuds’s picture

No, doesn't seem to be applied looking at the source code.

  • scott_euser committed 75756358 on 8.x-1.x authored by Matt B
    Issue #3113634 by Ruuds, Matt B: Allow choosing an Options email as...
scott_euser’s picture

Status: Needs work » Fixed

Apologies for the huge delay here. The clients I work for have all switched to Webform, so I will mark this module as seeking co-maintainers to help speed things up in the future.

matt b’s picture

Thank you!

ruuds’s picture

Thanks!

Status: Fixed » Closed (fixed)

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