Fix default confirmation message missing in new forms

[MAILPOET-3853]
This commit is contained in:
Pavel Dohnal
2021-11-03 10:01:17 +01:00
committed by Veljko V
parent ddad97ccfc
commit b30a8de9ca
3 changed files with 29 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
namespace MailPoet\Form\Templates;
use MailPoet\Entities\FormEntity;
use MailPoet\Settings\SettingsController;
use MailPoet\Util\CdnAssetUrl;
use MailPoet\Util\Helpers;
use MailPoet\WP\Functions as WPFunctions;
@@ -91,12 +92,17 @@ EOL;
/** @var string */
protected $assetsDirectory = '';
/** @var SettingsController */
private $settings;
public function __construct(
CdnAssetUrl $cdnAssetUrl,
SettingsController $settings,
WPFunctions $wp
) {
$this->cdnAssetUrl = $cdnAssetUrl;
$this->wp = $wp;
$this->settings = $settings;
}
abstract public function getName(): string;
@@ -123,9 +129,21 @@ EOL;
$formEntity->setBody($this->getBody());
$formEntity->setSettings($this->getSettings());
$formEntity->setStyles($this->getStyles());
$settings = $formEntity->getSettings();
if (!isset($settings['success_message']) || !($settings['success_message'])) {
$settings['success_message'] = $this->getDefaultSuccessMessage();
$formEntity->setSettings($settings);
}
return $formEntity;
}
private function getDefaultSuccessMessage() {
if ($this->settings->get('signup_confirmation.enabled')) {
return __('Check your inbox or spam folder to confirm your subscription.', 'mailpoet');
}
return __('Youve been successfully subscribed to our newsletter!', 'mailpoet');
}
protected function getAssetUrl(string $filename): string {
return $this->cdnAssetUrl->generateCdnUrl("form-templates/{$this->assetsDirectory}/$filename");
}

View File

@@ -63,6 +63,7 @@ use MailPoet\Form\Templates\Templates\Template7FixedBar;
use MailPoet\Form\Templates\Templates\Template7Popup;
use MailPoet\Form\Templates\Templates\Template7SlideIn;
use MailPoet\Form\Templates\Templates\Template7Widget;
use MailPoet\Settings\SettingsController;
use MailPoet\UnexpectedValueException;
use MailPoet\Util\CdnAssetUrl;
use MailPoet\WP\Functions as WPFunctions;
@@ -76,6 +77,10 @@ class TemplateRepository {
/** @var WPFunctions */
private $wp;
/** @var SettingsController */
private $settings;
private $templates = [
InitialForm::ID => InitialForm::class,
Template1BelowPages::ID => Template1BelowPages::class,
@@ -142,10 +147,12 @@ class TemplateRepository {
public function __construct(
CdnAssetUrl $cdnAssetUrl,
SettingsController $settings,
WPFunctions $wp
) {
$this->cdnAssetUrl = $cdnAssetUrl;
$this->wp = $wp;
$this->settings = $settings;
}
public function getFormTemplate(string $templateId): FormTemplate {
@@ -154,7 +161,7 @@ class TemplateRepository {
->withErrors(["Template with id $templateId doesn't exist."]);
}
/** @var FormTemplate $template */
$template = new $this->templates[$templateId]($this->cdnAssetUrl, $this->wp);
$template = new $this->templates[$templateId]($this->cdnAssetUrl, $this->settings, $this->wp);
return $template;
}

View File

@@ -4,6 +4,7 @@ namespace MailPoet\Test\Form\Templates;
use MailPoet\Form\Templates\FormTemplate;
use MailPoet\Form\Templates\TemplateRepository;
use MailPoet\Settings\SettingsController;
use MailPoet\Util\CdnAssetUrl;
use MailPoet\WP\Functions as WPFunctions;
@@ -17,7 +18,8 @@ class TemplatesRepositoryTest extends \MailPoetUnitTest {
$cdnAssetsMock->method('generateCdnUrl')
->willReturn('http://example.com/image.png');
$wpMock = $this->createMock(WPFunctions::class);
$this->repository = new TemplateRepository($cdnAssetsMock, $wpMock);
$settings = $this->createMock(SettingsController::class);
$this->repository = new TemplateRepository($cdnAssetsMock, $settings, $wpMock);
}
public function testItCanBuildFormTemplate() {