Refactor Form\Utils\Styles to injectable service
[MAILPOET-2451]
This commit is contained in:
committed by
Jack Kitterhing
parent
d25de883e7
commit
effd37a0ad
@@ -15,11 +15,11 @@ class Renderer {
|
||||
}
|
||||
|
||||
static function renderStyles($form = [], $prefix = null) {
|
||||
$styles = new Util\Styles(static::getStyles($form));
|
||||
$styles = new Util\Styles();
|
||||
|
||||
$html = '<style type="text/css">';
|
||||
$html .= '.mailpoet_hp_email_label{display:none;}'; // move honeypot field out of sight
|
||||
$html .= $styles->render($prefix);
|
||||
$html .= $styles->render(static::getStyles($form), $prefix);
|
||||
$html .= '</style>';
|
||||
|
||||
return $html;
|
||||
@@ -37,7 +37,8 @@ class Renderer {
|
||||
&& strlen(trim($form['styles'])) > 0) {
|
||||
return strip_tags($form['styles']);
|
||||
} else {
|
||||
return Util\Styles::$default_styles;
|
||||
$styles = new Util\Styles();
|
||||
return $styles->getDefaultStyles();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -6,7 +6,7 @@ use MailPoetVendor\Sabberworm\CSS\Parser as CSSParser;
|
||||
|
||||
class Styles {
|
||||
public $styles;
|
||||
static $default_styles = <<<EOL
|
||||
private $default_styles = <<<EOL
|
||||
/* form */
|
||||
.mailpoet_form {
|
||||
|
||||
@@ -79,15 +79,14 @@ class Styles {
|
||||
background-color: #5b5b5b;
|
||||
}
|
||||
EOL;
|
||||
private $stylesheet;
|
||||
|
||||
function __construct($stylesheet = null) {
|
||||
$this->stylesheet = $stylesheet;
|
||||
function getDefaultStyles() {
|
||||
return $this->default_styles;
|
||||
}
|
||||
|
||||
function render($prefix = '') {
|
||||
if (!$this->stylesheet) return;
|
||||
$styles = new CSSParser($this->stylesheet);
|
||||
function render($stylesheet, $prefix = '') {
|
||||
if (!$stylesheet) return;
|
||||
$styles = new CSSParser($stylesheet);
|
||||
$styles = $styles->parse();
|
||||
$formatted_styles = [];
|
||||
foreach ($styles->getAllDeclarationBlocks() as $style_declaration) {
|
||||
|
Reference in New Issue
Block a user