Add label to text form
[MAILPOET-3331]
This commit is contained in:
@@ -104,28 +104,39 @@ class BlockRendererHelper {
|
||||
|
||||
public function renderLabel(array $block, array $formSettings): string {
|
||||
$html = '';
|
||||
$forId = '';
|
||||
|
||||
if (
|
||||
isset($block['params']['hide_label'])
|
||||
&& $block['params']['hide_label']
|
||||
) {
|
||||
return $html;
|
||||
}
|
||||
if (
|
||||
isset($block['params']['label_within'])
|
||||
&& $block['params']['label_within']
|
||||
) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
$automationId = null;
|
||||
if (in_array($block['id'], ['email', 'last_name', 'first_name'], true)) {
|
||||
$automationId = 'data-automation-id="form_' . $block['id'] . '_label" ';
|
||||
if (isset($formSettings['id'])) {
|
||||
$forId = 'for="form_' . $block['id'] . '_' . $formSettings['id'] . '" ';
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
isset($block['params']['label'])
|
||||
&& strlen(trim($block['params']['label'])) > 0
|
||||
) {
|
||||
$labelClass = 'class="mailpoet_' . $block['type'] . '_label" ';
|
||||
|
||||
if (
|
||||
isset($block['params']['label_within'])
|
||||
&& $block['params']['label_within']
|
||||
) {
|
||||
$labelClass = 'class="screen-reader-text" ';
|
||||
}
|
||||
|
||||
$html .= '<label '
|
||||
. 'class="mailpoet_' . $block['type'] . '_label" '
|
||||
. $forId
|
||||
. $labelClass
|
||||
. $this->renderFontStyle($formSettings, $block['styles'] ?? [])
|
||||
. ($automationId ?? '')
|
||||
. '>';
|
||||
|
@@ -34,6 +34,7 @@ class Text {
|
||||
public function render(array $block, array $formSettings): string {
|
||||
$type = 'text';
|
||||
$automationId = ' ';
|
||||
$id = '';
|
||||
$autocomplete = 'on';
|
||||
if ($block['id'] === 'email') {
|
||||
$type = 'email';
|
||||
@@ -41,20 +42,26 @@ class Text {
|
||||
}
|
||||
|
||||
if (in_array($block['id'], ['email', 'last_name', 'first_name'], true)) {
|
||||
|
||||
$automationId = 'data-automation-id="form_' . $this->wp->escAttr($block['id']) . '" ';
|
||||
|
||||
if (isset($formSettings['id'])) {
|
||||
$id = 'id="form_' . $this->wp->escAttr($block['id']) . '_' . $this->wp->escAttr($formSettings['id']) . '" ';
|
||||
}
|
||||
}
|
||||
|
||||
$styles = $this->inputStylesRenderer->renderForTextInput($block['styles'] ?? [], $formSettings);
|
||||
|
||||
$name = $this->rendererHelper->getFieldName($block);
|
||||
|
||||
$html = '';
|
||||
$html .= $this->inputStylesRenderer->renderPlaceholderStyles($block, 'input[name="data[' . $name . ']"]');
|
||||
$html = $this->inputStylesRenderer->renderPlaceholderStyles($block, 'input[name="data[' . $name . ']"]');
|
||||
|
||||
$html .= $this->rendererHelper->renderLabel($block, $formSettings);
|
||||
|
||||
$html .= '<input type="' . $type . '" autocomplete="' . $autocomplete . '" class="mailpoet_text" ';
|
||||
|
||||
$html .= $id;
|
||||
|
||||
$html .= 'name="data[' . $name . ']" ';
|
||||
|
||||
$html .= 'title="' . $this->rendererHelper->getFieldLabel($block) . '" ';
|
||||
|
@@ -101,6 +101,9 @@ class BlocksRenderer {
|
||||
|
||||
public function renderBlock(array $block, array $formSettings, ?int $formId): string {
|
||||
$html = '';
|
||||
if ($formId) {
|
||||
$formSettings['id'] = $formId;
|
||||
}
|
||||
switch ($block['type']) {
|
||||
case FormEntity::HTML_BLOCK_TYPE:
|
||||
$html .= $this->html->render($block, $formSettings);
|
||||
|
Reference in New Issue
Block a user