From 3923ec325d5e680ca1e3d3b6d9b611e8c4fe71ac Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Tue, 11 Dec 2012 17:09:02 +1300 Subject: [PATCH] Adding ability to extend EmailRecipients so they can be filtered --- code/model/UserDefinedForm.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/code/model/UserDefinedForm.php b/code/model/UserDefinedForm.php index fac6eaa..3c498a5 100755 --- a/code/model/UserDefinedForm.php +++ b/code/model/UserDefinedForm.php @@ -212,7 +212,23 @@ class UserDefinedForm extends Page { parent::doRevertToLive(); } - + + /** + * Allow overriding the EmailRecipients on a {@link DataExtension} + * so you can customise who receives an email. + * Converts the RelationList to an ArrayList so that manipulation + * of the original source data isn't possible. + * + * @return ArrayList + */ + public function FilteredEmailRecipients() { + $recipients = new ArrayList($this->getComponents('EmailRecipients')->toArray()); + + $this->extend('updateFilteredEmailRecipients', $recipients); + + return $recipients; + } + /** * Duplicate this UserDefinedForm page, and its form fields. * Submissions, on the other hand, won't be duplicated. @@ -242,7 +258,7 @@ class UserDefinedForm extends Page { return $page; } - + /** * Custom options for the form. You can extend the built in options by * using {@link updateFormOptions()} @@ -794,7 +810,7 @@ JS ); // email users on submit. - if($this->EmailRecipients()) { + if($this->FilteredEmailRecipients()) { $email = new UserDefinedForm_SubmittedFormEmail($submittedFields); $email->populateTemplate($emailData); @@ -806,7 +822,7 @@ JS } } - foreach($this->EmailRecipients() as $recipient) { + foreach($this->FilteredEmailRecipients() as $recipient) { $email->populateTemplate($recipient); $email->populateTemplate($emailData); $email->setFrom($recipient->EmailFrom);