From 73281f08515fbfbd1d20cf2caa10f5845f794a1b Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Wed, 29 Jan 2020 16:27:02 +0100 Subject: [PATCH] Inject settings and style utils to renderer using constructor [MAILPOET-2665] --- lib/Form/Renderer.php | 24 ++++++++++++++++-------- lib/Form/Widget.php | 3 ++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/Form/Renderer.php b/lib/Form/Renderer.php index 75b60be740..807b3269ee 100644 --- a/lib/Form/Renderer.php +++ b/lib/Form/Renderer.php @@ -2,17 +2,27 @@ namespace MailPoet\Form; +use MailPoet\Form\Util\Styles; use MailPoet\Settings\SettingsController; use MailPoet\Subscription\Captcha; use MailPoet\WP\Functions as WPFunctions; class Renderer { - public function renderStyles(array $form = [], string $prefix = null): string { - $styles = new Util\Styles(); + /** @var Styles */ + private $styleUtils; + /** @var SettingsController */ + private $settings; + + public function __construct(Styles $styleUtils, SettingsController $settings) { + $this->styleUtils = $styleUtils; + $this->settings = $settings; + } + + public function renderStyles(array $form = [], string $prefix = null): string { $html = ''; return $html; @@ -30,20 +40,18 @@ class Renderer { && strlen(trim($form['styles'])) > 0) { return strip_tags($form['styles']); } else { - $styles = new Util\Styles(); - return $styles->getDefaultStyles(); + return $this->styleUtils->getDefaultStyles(); } } public function renderBlocks(array $blocks = [], bool $honeypotEnabled = true): string { - $settings = SettingsController::getInstance(); // add honeypot for spambots $html = ($honeypotEnabled) ? '' : ''; foreach ($blocks as $key => $block) { - if ($block['type'] == 'submit' && $settings->get('captcha.type') === Captcha::TYPE_RECAPTCHA) { - $siteKey = $settings->get('captcha.recaptcha_site_token'); + if ($block['type'] == 'submit' && $this->settings->get('captcha.type') === Captcha::TYPE_RECAPTCHA) { + $siteKey = $this->settings->get('captcha.recaptcha_site_token'); $html .= '