Skip to content

Commit

Permalink
Merge pull request #2 from signify-nz/fix/doc003-35--disable-locale-f…
Browse files Browse the repository at this point in the history
…ilter

fix: Disable locale filter in Member admin
  • Loading branch information
LeviWB authored Feb 17, 2021
2 parents 2f8ae85 + 6a4a5d7 commit 2259409
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion code/email/MailblockMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ public function sendHTML($to, $from, $subject, $htmlContent,
protected function mailblockRewrite($recipients, $subject, $customHeaders) {
// Get the correct mailblock config.
if (class_exists('Subsite')) {
// Disable the locale filter if Translatable uses the wrong locale.
$badTranslatable = $this->hasBadTranslatable();
if ($badTranslatable) {
$enabled = Translatable::disable_locale_filter();
}
$mainSiteConfig = SiteConfig::get()->filter('SubsiteID', 0)->first();
// Re-enable the locale filter if it was disabled.
if ($badTranslatable) {
Translatable::enable_locale_filter($enabled);
}
}
else {
$mainSiteConfig = SiteConfig::current_site_config();
Expand Down Expand Up @@ -101,7 +110,7 @@ protected function mailblockRewrite($recipients, $subject, $customHeaders) {
$newRecipients = implode(', ', preg_split("/\r\n|\n|\r/",
$mailblockRecipients
));
// If one of the orignial recipients is in the whitelist, add them
// If one of the original recipients is in the whitelist, add them
// to the new recipients list.
$mailblockWhitelist = $siteConfig->getField('MailblockWhitelist');
$whitelist = preg_split("/\r\n|\n|\r/", $mailblockWhitelist);
Expand Down Expand Up @@ -132,4 +141,17 @@ protected function mailblockRewrite($recipients, $subject, $customHeaders) {
);
return $rewrites;
}

/**
* Is Translatable installed, and does it misbehave in the current scenario.
*
* When creating a member the locale is temporarily changed which
* interferes with subsite retrieval.
*
* @return boolean
*/
private function hasBadTranslatable() {
return class_exists('Translatable')
&& Director::get_current_page() instanceof SecurityAdmin;
}
}

0 comments on commit 2259409

Please sign in to comment.