PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.2.3
JetFormBuilder — Dynamic Blocks Form Builder v3.2.3
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / blocks / render / radio-field-render.php
jetformbuilder / includes / blocks / render Last commit date
action-button-render.php 2 years ago base-select-radio-check.php 2 years ago base.php 2 years ago calculated-field-render.php 2 years ago checkbox-field-render.php 2 years ago date-field-render.php 2 years ago datetime-field-render.php 2 years ago form-builder.php 2 years ago form-hidden-fields.php 2 years ago group-break-field-render.php 2 years ago heading-field-render.php 2 years ago media-field-render.php 2 years ago number-field-render.php 2 years ago radio-field-render.php 2 years ago range-field-render.php 2 years ago repeater-field-render.php 2 years ago select-field-render.php 2 years ago text-field-render.php 2 years ago textarea-field-render.php 2 years ago time-field-render.php 2 years ago
radio-field-render.php
167 lines
1 <?php
2
3 namespace Jet_Form_Builder\Blocks\Render;
4
5 // If this file is called directly, abort.
6 use Jet_Form_Builder\Classes\Builder_Helper;
7
8 if ( ! defined( 'WPINC' ) ) {
9 die;
10 }
11
12 /**
13 * Define text field renderer class
14 */
15 class Radio_Field_Render extends Base_Select_Radio_Check {
16
17 public function __construct( $block_type ) {
18 parent::__construct( $block_type );
19
20 $this->set_options();
21 }
22
23 public function get_name() {
24 return 'radio-field';
25 }
26
27 public function render_without_layout( $template = null, $args = array() ) {
28 parent::render_without_layout( $template, $args );
29
30 return $this->render_options();
31 }
32
33 public function render_options(): string {
34 $required = $this->block_type->get_required_val();
35
36 $this->add_attribute( 'class', 'jet-form-builder__field radio-field checkradio-field' );
37 $this->add_attribute( 'class', $this->args['class_name'] );
38 $this->add_attribute( 'required', $required );
39
40 $html = '<div class="jet-form-builder__fields-group checkradio-wrap" data-jfb-sync>';
41
42 if ( ! empty( $this->args['field_options'] ) ) {
43 foreach ( $this->args['field_options'] as $value => $option ) {
44 $html .= $this->render_option( $value, $option );
45 }
46 }
47
48 if ( ! empty( $this->args['custom_option'] ) ) {
49 $html .= $this->render_custom_option();
50 }
51
52 $html .= '</div>';
53 $this->reset_attributes();
54
55 return $html;
56 }
57
58 public function render_option( $value, $option ): string {
59 $default = (string) ( $this->args['default'] ?? false );
60
61 if ( is_array( $option ) ) {
62 $val = $option['value'] ?? $value;
63 $label = $option['label'] ?? $val;
64 } else {
65 $val = $value;
66 $label = $option;
67 }
68
69 $html = '<div class="jet-form-builder__field-wrap radio-wrap checkradio-wrap">';
70
71 $item = sprintf(
72 '<label class="jet-form-builder__field-label for-radio">
73 <input %1$s %2$s><span>%3$s</span></label>',
74 Builder_Helper::attrs(
75 array(
76 array( 'type', 'radio' ),
77 array( 'name', esc_attr( $this->block_type->get_field_name() ) ),
78 array( 'value', esc_attr( $val ) ),
79 array( 'data-field-name', esc_attr( $this->args['name'] ) ),
80 array( 'checked', ( (string) $val ) === $default ? 'checked' : '' ),
81 array(
82 'data-calculate',
83 ( is_array( $option ) && isset( $option['calculate'] ) && '' !== $option['calculate'] )
84 ? esc_attr( $option['calculate'] )
85 : '',
86 ),
87 )
88 ),
89 $this->get_attributes_string_save(),
90 wp_kses_post( $label )
91 );
92
93 /**
94 * @since 3.1.0
95 */
96 $html .= apply_filters(
97 'jet-form-builder/render/radio-field/option',
98 $item,
99 $val,
100 $option,
101 $this
102 );
103
104 $html .= '</div>';
105
106 return $html;
107 }
108
109 protected function render_custom_option(): string {
110 $html = '<div class="jet-form-builder__field-wrap radio-wrap checkradio-wrap custom-option">';
111 $class_name = $this->args['class_name'] ?? '';
112
113 $item = sprintf(
114 '<label class="jet-form-builder__field-label for-radio">
115 <input %1$s value=""><span>%2$s</span></label>',
116 Builder_Helper::attrs(
117 array(
118 array( 'type', 'radio' ),
119 array( 'name', esc_attr( $this->block_type->get_field_name() ) ),
120 array( 'data-field-name', esc_attr( $this->args['name'] ) ),
121 array( 'data-custom', 1 ),
122 array(
123 'class',
124 'jet-form-builder__field radio-field checkradio-field' . ( $class_name ? " {$class_name}" : '' ),
125 ),
126 )
127 ),
128 sprintf(
129 '<input %s>',
130 Builder_Helper::attrs(
131 array(
132 array( 'type', 'text' ),
133 array( 'name', esc_attr( $this->block_type->get_field_name() ) ),
134 array( 'data-field-name', esc_attr( $this->args['name'] ) ),
135 array( 'class', 'jet-form-builder__field text-field' ),
136 array( 'disabled', 'disabled' ),
137 array( 'required', $this->block_type->get_required_val() ),
138 )
139 )
140 )
141 );
142
143 /**
144 * @since 3.2.0
145 */
146 $html .= apply_filters(
147 'jet-form-builder/render/radio-field/custom-option',
148 $item,
149 $this
150 );
151
152 $html .= '</div>';
153
154 return $html;
155 }
156
157 /**
158 * @see \Jet_Form_Builder\Blocks\Render\Calculated_Field_Render::get_fields_label_tag
159 *
160 * @return string
161 */
162 protected function get_fields_label_tag(): string {
163 return 'div';
164 }
165
166 }
167