PluginProbe
MailPoet – Newsletters, Email Marketing, and Automation / 3.7.4
MailPoet – Newsletters, Email Marketing, and Automation v3.7.4
5.38.0 5.37.0 5.36.1 5.36.0 5.35.1 5.35.0 5.34.3 5.34.2 5.34.1 5.34.0 5.33.1 5.33.0 5.32.0 5.31.0 5.30.0 5.29.0 5.28.1 5.28.0 5.27.0 5.26.0 5.26.1 5.25.0 5.24.0 4.43.0 4.43.1 All 542 releases
mailpoet / lib / Form / Block / Select.php

Select.php in MailPoet – Newsletters, Email Marketing, and Automation 3.7.4, at lib/Form/Block/Select.php

62 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace MailPoet\Form\Block;
3
4 if(!defined('ABSPATH')) exit;
5
6 class Select extends Base {
7
8 static function render($block) {
9 $html = '';
10
11 $field_name = 'data[' . static::getFieldName($block) . ']';
12 $field_validation = static::getInputValidation($block);
13 $automation_id = ($block['id'] == 'status') ? 'data-automation-id="form_status"' : '';
14 $html .= '<p class="mailpoet_paragraph">';
15 $html .= static::renderLabel($block);
16 $html .= '<select class="mailpoet_select" name="'.$field_name.'" ' . $automation_id . '>';
17
18 if(isset($block['params']['label_within']) && $block['params']['label_within']) {
19 $html .= '<option value="">'.static::getFieldLabel($block).'</option>';
20 } else {
21 if(empty($block['params']['required']) || !$block['params']['required']) {
22 $html .= '<option value="">-</option>';
23 }
24 }
25
26 $options = (!empty($block['params']['values'])
27 ? $block['params']['values']
28 : array()
29 );
30
31 foreach($options as $option) {
32 if(!empty($option['is_hidden'])) {
33 continue;
34 }
35
36 $is_selected = (
37 (isset($option['is_checked']) && $option['is_checked'])
38 ||
39 (self::getFieldValue($block) === $option['value'])
40 ) ? ' selected="selected"' : '';
41
42 $is_disabled = (!empty($option['is_disabled'])) ? ' disabled="disabled"' : '';
43
44 if(is_array($option['value'])) {
45 $value = key($option['value']);
46 $label = reset($option['value']);
47 } else {
48 $value = $option['value'];
49 $label = $option['value'];
50 }
51
52 $html .= '<option value="'.$value.'"' . $is_selected . $is_disabled . '>';
53 $html .= esc_attr($label);
54 $html .= '</option>';
55 }
56 $html .= '</select>';
57
58 $html .= '</p>';
59
60 return $html;
61 }
62 }