diff --git a/CHANGELOG.md b/CHANGELOG.md index d5243202..d9429799 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Release Notes for Campaign -## 3.5.6 - Unreleased +## 3.5.6 - 2024-10-31 + +### Changed + +- The “from names and emails” setting now accepts environment variables ([#503](https://github.com/putyourlightson/craft-campaign/issues/503)). ### Fixed diff --git a/src/Campaign.php b/src/Campaign.php index cead1539..8f633f76 100644 --- a/src/Campaign.php +++ b/src/Campaign.php @@ -390,8 +390,8 @@ protected function createSettingsModel(): SettingsModel $settings->apiKey = StringHelper::randomString(16); $settings->fromNamesEmails = [ [ - App::parseEnv($mailSettings->fromName), - App::parseEnv($mailSettings->fromEmail), + $mailSettings->fromName, + $mailSettings->fromEmail, '', Craft::$app->getSites()->getPrimarySite()->id, ], diff --git a/src/helpers/SettingsHelper.php b/src/helpers/SettingsHelper.php index 3a2b0535..5aad9dcb 100755 --- a/src/helpers/SettingsHelper.php +++ b/src/helpers/SettingsHelper.php @@ -38,7 +38,7 @@ public static function getFromNameEmail(int $siteId = null): array { // Get first from name and email $firstFromNameEmail = []; - $fromNamesEmails = Campaign::$plugin->settings->fromNamesEmails; + $fromNamesEmails = Campaign::$plugin->settings->getFromNamesEmails(); foreach ($fromNamesEmails as $fromNameEmail) { if ($siteId === null || empty($fromNameEmail[3]) || $fromNameEmail[3] == $siteId) { @@ -57,9 +57,9 @@ public static function getFromNameEmail(int $siteId = null): array $mailSettings = App::mailSettings(); $firstFromNameEmail = [ - 'name' => $mailSettings->fromName, - 'email' => $mailSettings->fromEmail, - 'replyTo' => '', + 'name' => App::parseEnv($mailSettings->fromName), + 'email' => App::parseEnv($mailSettings->fromEmail), + 'replyTo' => App::parseEnv($mailSettings->replyToEmail), ]; } @@ -72,7 +72,7 @@ public static function getFromNameEmail(int $siteId = null): array public static function getFromNameEmailOptions(int $siteId = null): array { $fromNameEmailOptions = []; - $fromNamesEmails = Campaign::$plugin->settings->fromNamesEmails; + $fromNamesEmails = Campaign::$plugin->settings->getFromNamesEmails(); foreach ($fromNamesEmails as $fromNameEmail) { $fromSiteId = $fromNameEmail[3] ?? null; diff --git a/src/models/SettingsModel.php b/src/models/SettingsModel.php index 9ea4dd5f..50d18c09 100644 --- a/src/models/SettingsModel.php +++ b/src/models/SettingsModel.php @@ -417,6 +417,26 @@ public function getTurnstileErrorMessage(): string return App::parseEnv($this->turnstileErrorMessage) ?? ''; } + /** + * Returns the parsed from names and emails. + * + * @since 3.5.6 + */ + public function getFromNamesEmails(): array + { + $fromNamesEmails = []; + foreach ($this->fromNamesEmails as $fromNameEmail) { + $fromNamesEmails[] = [ + App::parseEnv($fromNameEmail[0]) ?? '', + App::parseEnv($fromNameEmail[1]) ?? '', + App::parseEnv($fromNameEmail[2]) ?? '', + $fromNameEmail[3] ?? null, + ]; + } + + return $fromNamesEmails; + } + /** * Returns the contact field layout. */ @@ -469,12 +489,14 @@ public function getContactFields(): array */ public function validateFromNamesEmails(mixed $attribute): void { - if (empty($this->fromNamesEmails)) { + $fromNamesEmails = $this->getFromNamesEmails(); + + if (empty($fromNamesEmails)) { $this->addError($attribute, Craft::t('campaign', 'You must enter at least one name and email.')); return; } - foreach ($this->fromNamesEmails as $fromNameEmail) { + foreach ($fromNamesEmails as $fromNameEmail) { if ($fromNameEmail[0] === '' || $fromNameEmail[1] === '') { $this->addError($attribute, Craft::t('campaign', 'The name and email cannot be blank.')); return;