Files
piratepoet/lib/Form/Block/Radio.php
2016-03-17 15:45:05 +01:00

55 lines
1.3 KiB
PHP

<?php
namespace MailPoet\Form\Block;
class Radio extends Base {
static function render($block) {
$html = '';
$field_name = static::getFieldName($block);
$field_validation = static::getInputValidation($block);
$html .= '<p class="mailpoet_paragraph">';
$html .= static::renderLabel($block);
$options = (!empty($block['params']['values'])
? $block['params']['values']
: array()
);
foreach($options as $option) {
$html .= '<label class="mailpoet_radio_label">';
$html .= '<input type="radio" class="mailpoet_radio" ';
$html .= 'name="'.$field_name.'" ';
if(is_array($option['value'])) {
$value = key($option['value']);
$label = reset($option['value']);
} else {
$value = $option['value'];
$label = $option['value'];
}
$html .= 'value="'.esc_attr($value).'" ';
$html .= (
(isset($option['is_checked']) && $option['is_checked'])
||
(self::getFieldValue($block) === $value)
) ? 'checked="checked"' : '';
$html .= $field_validation;
$html .= ' /> '.esc_attr($label);
$html .= '</label>';
}
$html .= '<span class="mailpoet_error_'.$block['id'].'"></span>';
$html .= '</p>';
return $html;
}
}