<?php namespace MailPoet\Form\Block; if (!defined('ABSPATH')) exit; use MailPoet\Form\BlockWrapperRenderer; use MailPoet\WP\Functions as WPFunctions; class Radio { /** @var BlockRendererHelper */ private $rendererHelper; /** @var WPFunctions */ private $wp; /** @var BlockWrapperRenderer */ private $wrapper; public function __construct( BlockRendererHelper $rendererHelper, BlockWrapperRenderer $wrapper, WPFunctions $wp ) { $this->rendererHelper = $rendererHelper; $this->wrapper = $wrapper; $this->wp = $wp; } public function render(array $block, array $formSettings): string { $html = ''; $fieldName = 'data[' . $this->rendererHelper->getFieldName($block) . ']'; $fieldValidation = $this->rendererHelper->getInputValidation($block); $html .= $this->rendererHelper->renderLabel($block, $formSettings); $options = (!empty($block['params']['values']) ? $block['params']['values'] : [] ); $selectedValue = $this->rendererHelper->getFieldValue($block); foreach ($options as $option) { $html .= '<label class="mailpoet_radio_label" ' . $this->rendererHelper->renderFontStyle($formSettings) . '>'; $html .= '<input type="radio" class="mailpoet_radio" '; $html .= 'name="' . $fieldName . '" '; if (is_array($option['value'])) { $value = key($option['value']); $label = reset($option['value']); } else { $value = $option['value']; $label = $option['value']; } $html .= 'value="' . $this->wp->escAttr($value) . '" '; $html .= ( ( $selectedValue === '' && isset($option['is_checked']) && $option['is_checked'] ) || ($selectedValue === $value) ) ? 'checked="checked"' : ''; $html .= $fieldValidation; $html .= ' /> ' . $this->wp->escAttr($label); $html .= '</label>'; } $html .= '<span class="mailpoet_error_' . $block['id'] . '"></span>'; return $this->wrapper->render($block, $html); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
BlockRendererHelper.php | File | 6.65 KB | 0644 |
|
Checkbox.php | File | 1.79 KB | 0644 |
|
Column.php | File | 1.85 KB | 0644 |
|
Columns.php | File | 1.81 KB | 0644 |
|
Date.php | File | 7.46 KB | 0644 |
|
Divider.php | File | 1.88 KB | 0644 |
|
Heading.php | File | 2.85 KB | 0644 |
|
Html.php | File | 928 B | 0644 |
|
Image.php | File | 2.88 KB | 0644 |
|
Paragraph.php | File | 2.54 KB | 0644 |
|
Radio.php | File | 2.02 KB | 0644 |
|
Segment.php | File | 2.45 KB | 0644 |
|
Select.php | File | 2.67 KB | 0644 |
|
Submit.php | File | 1.59 KB | 0644 |
|
Text.php | File | 2.26 KB | 0644 |
|
Textarea.php | File | 1.84 KB | 0644 |
|
index.php | File | 0 B | 0644 |
|