Render bold labels according to styles settings
[MAILPOET-2599]
This commit is contained in:
committed by
Veljko V
parent
4e8fda670c
commit
760aed407f
@ -100,7 +100,7 @@ class BlockRendererHelper {
|
|||||||
&& strlen(trim($block['params']['label'])) > 0) {
|
&& strlen(trim($block['params']['label'])) > 0) {
|
||||||
$html .= '<label '
|
$html .= '<label '
|
||||||
. 'class="mailpoet_' . $block['type'] . '_label" '
|
. 'class="mailpoet_' . $block['type'] . '_label" '
|
||||||
. $this->renderFontStyle($formSettings)
|
. $this->renderFontStyle($formSettings, $block['styles'] ?? [])
|
||||||
. '>';
|
. '>';
|
||||||
$html .= htmlspecialchars($block['params']['label']);
|
$html .= htmlspecialchars($block['params']['label']);
|
||||||
|
|
||||||
@ -113,13 +113,16 @@ class BlockRendererHelper {
|
|||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderFontStyle(array $formSettings) {
|
public function renderFontStyle(array $formSettings, array $styles = []) {
|
||||||
|
$rules = [];
|
||||||
if (isset($formSettings['fontSize'])) {
|
if (isset($formSettings['fontSize'])) {
|
||||||
return 'style="'
|
$rules[] = 'font-size: ' . trim($formSettings['fontSize']) . 'px;';
|
||||||
. 'font-size: ' . trim($formSettings['fontSize']) . 'px;'
|
$rules[] = 'line-height: ' . trim($formSettings['fontSize']) * 1.2 . 'px";';
|
||||||
. '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 {
|
public function renderInputPlaceholder(array $block): string {
|
||||||
|
@ -45,7 +45,12 @@ class BlockRendererHelperTest extends \MailPoetUnitTest {
|
|||||||
$label = $this->rendererHelper->renderLabel($block, []);
|
$label = $this->rendererHelper->renderLabel($block, []);
|
||||||
expect($label)->regExp('#<label.*class="mailpoet_text_label".*>Input label</label>#m');
|
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['params']['required'] = '1';
|
||||||
|
$block['styles'] = [];
|
||||||
$label = $this->rendererHelper->renderLabel($block, []);
|
$label = $this->rendererHelper->renderLabel($block, []);
|
||||||
expect($label)->equals('<label class="mailpoet_text_label" >Input label <span class="mailpoet_required">*</span></label>');
|
expect($label)->equals('<label class="mailpoet_text_label" >Input label <span class="mailpoet_required">*</span></label>');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user