Render bold labels according to styles settings

[MAILPOET-2599]
This commit is contained in:
Rostislav Wolny
2020-03-05 14:50:19 +01:00
committed by Veljko V
parent 4e8fda670c
commit 760aed407f
2 changed files with 14 additions and 6 deletions

View File

@ -100,7 +100,7 @@ class BlockRendererHelper {
&& strlen(trim($block['params']['label'])) > 0) {
$html .= '<label '
. 'class="mailpoet_' . $block['type'] . '_label" '
. $this->renderFontStyle($formSettings)
. $this->renderFontStyle($formSettings, $block['styles'] ?? [])
. '>';
$html .= htmlspecialchars($block['params']['label']);
@ -113,13 +113,16 @@ class BlockRendererHelper {
return $html;
}
public function renderFontStyle(array $formSettings) {
public function renderFontStyle(array $formSettings, array $styles = []) {
$rules = [];
if (isset($formSettings['fontSize'])) {
return 'style="'
. 'font-size: ' . trim($formSettings['fontSize']) . 'px;'
. 'line-height: ' . trim($formSettings['fontSize']) * 1.2 . 'px";';
$rules[] = 'font-size: ' . trim($formSettings['fontSize']) . 'px;';
$rules[] = 'line-height: ' . trim($formSettings['fontSize']) * 1.2 . 'px";';
}
return '';
if (isset($styles['bold'])) {
$rules[] = 'font-weight: bold;';
}
return $rules ? 'style="' . implode("", $rules) . '"' : '';
}
public function renderInputPlaceholder(array $block): string {

View File

@ -45,7 +45,12 @@ class BlockRendererHelperTest extends \MailPoetUnitTest {
$label = $this->rendererHelper->renderLabel($block, []);
expect($label)->regExp('#<label.*class="mailpoet_text_label".*>Input label</label>#m');
$block['styles'] = ['bold' => '1'];
$label = $this->rendererHelper->renderLabel($block, []);
expect($label)->equals('<label class="mailpoet_text_label" style="font-weight: bold;">Input label</label>');
$block['params']['required'] = '1';
$block['styles'] = [];
$label = $this->rendererHelper->renderLabel($block, []);
expect($label)->equals('<label class="mailpoet_text_label" >Input label <span class="mailpoet_required">*</span></label>');