Render styles for the form

[MAILPOET-2600]

Signed-off-by: Pavel Dohnal <pavel@mailpoet.com>
This commit is contained in:
Pavel Dohnal
2020-02-26 13:22:29 +01:00
committed by Jack Kitterhing
parent b49ce7d4e4
commit ce127eadc1
2 changed files with 92 additions and 1 deletions

View File

@ -37,7 +37,10 @@ class Renderer {
public function renderHTML(array $form = []): string {
if (isset($form['body']) && !empty($form['body'])) {
return $this->renderBlocks($form['body']);
return $this->wrapForm(
$this->renderBlocks($form['body']),
$form['settings']
);
}
return '';
}
@ -88,4 +91,23 @@ class Renderer {
<input class="mailpoet_recaptcha_field" type="hidden" name="recaptcha">
</div>';
}
private function wrapForm(string $formBody, array $formSettings): string {
$styles = [];
if (isset($formSettings['backgroundColor'])) {
$styles[] = 'background-color: ' . trim($formSettings['backgroundColor']);
}
if (isset($formSettings['fontColor'])) {
$styles[] = 'color: ' . trim($formSettings['fontColor']);
}
if (isset($formSettings['fontSize'])) {
$styles[] = 'font-size: ' . trim($formSettings['fontSize']) . 'px';
}
if (empty($styles)) return $formBody;
return '<div style="' . join(';', $styles) . '">' . $formBody . '</div>';
}
}