| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\FormBuilder\Actions; |
| 4 |
|
| 5 |
use Give\DonationForms\Models\DonationForm; |
| 6 |
|
| 7 |
/** |
| 8 |
* Update email template options on backwards compatible form meta. |
| 9 |
* |
| 10 |
* @since 3.0.0 |
| 11 |
*/ |
| 12 |
class UpdateEmailTemplateMeta |
| 13 |
{ |
| 14 |
/** |
| 15 |
* @since 3.0.0 |
| 16 |
* @param DonationForm $form |
| 17 |
*/ |
| 18 |
public function __invoke(DonationForm $form) |
| 19 |
{ |
| 20 |
foreach($form->settings->emailTemplateOptions as $emailType => $templateOptions) { |
| 21 |
|
| 22 |
$templateOptions['notification'] = $templateOptions['status']; |
| 23 |
unset($templateOptions['status']); |
| 24 |
|
| 25 |
if(isset($templateOptions['recipient'])) { |
| 26 |
$templateOptions['recipient'] = $this->formatRecipientEmails($templateOptions['recipient']); |
| 27 |
} |
| 28 |
|
| 29 |
foreach($templateOptions as $key => $value) { |
| 30 |
give()->form_meta->update_meta($form->id, "_give_{$emailType}_{$key}", $value); |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* @since 3.0.0 |
| 37 |
* @param array $emails |
| 38 |
* @return array |
| 39 |
*/ |
| 40 |
protected function formatRecipientEmails($emails): array |
| 41 |
{ |
| 42 |
return array_map(function($email) { |
| 43 |
return ['email' => $email]; |
| 44 |
}, $emails); |
| 45 |
} |
| 46 |
} |
| 47 |
|