Files
piratepoet/lib/Form/Block/Checkbox.php
Jan Jakeš 54549ff037 Convert variable names to camel case
[MAILPOET-1796]
2020-01-14 15:22:42 +01:00

54 lines
1.2 KiB
PHP

<?php
namespace MailPoet\Form\Block;
class Checkbox extends Base {
public static function render($block) {
$html = '';
$fieldName = 'data[' . static::getFieldName($block) . ']';
$fieldValidation = static::getInputValidation($block);
$html .= '<p class="mailpoet_paragraph">';
$html .= static::renderLabel($block);
$options = (!empty($block['params']['values'])
? $block['params']['values']
: []
);
$selectedValue = self::getFieldValue($block);
foreach ($options as $option) {
$html .= '<label class="mailpoet_checkbox_label">';
$html .= '<input type="checkbox" class="mailpoet_checkbox" ';
$html .= 'name="' . $fieldName . '" ';
$html .= 'value="1" ';
$html .= (
(
$selectedValue === ''
&& isset($option['is_checked'])
&& $option['is_checked']
) || ($selectedValue)
) ? 'checked="checked"' : '';
$html .= $fieldValidation;
$html .= ' /> ' . esc_attr($option['value']);
$html .= '</label>';
}
$html .= '<span class="mailpoet_error_' . $block['id'] . '"></span>';
$html .= '</p>';
return $html;
}
}