PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.7
JetFormBuilder — Dynamic Blocks Form Builder v3.4.7
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 / modules / option-field / blocks / radio / block-render.php
jetformbuilder / modules / option-field / blocks / radio Last commit date
block-render.php 2 years ago block-type.php 1 year ago
block-render.php
161 lines
1 <?php
2
3 namespace JFB_Modules\Option_Field\Blocks\Radio;
4
5 use Jet_Form_Builder\Blocks\Render\Base;
6 use Jet_Form_Builder\Classes\Builder_Helper;
7
8 // If this file is called directly, abort.
9 if ( ! defined( 'WPINC' ) ) {
10 die;
11 }
12
13 /**
14 * Define text field renderer class
15 */
16 class Block_Render extends Base {
17
18 public function get_name() {
19 return 'radio-field';
20 }
21
22 public function render_without_layout( $template = null, $args = array() ) {
23 parent::render_without_layout( $template, $args );
24
25 return $this->render_options();
26 }
27
28 public function render_options(): string {
29 $required = $this->block_type->get_required_val();
30
31 $this->add_attribute( 'class', 'jet-form-builder__field radio-field checkradio-field' );
32 $this->add_attribute( 'class', $this->args['class_name'] );
33 $this->add_attribute( 'required', $required );
34
35 $html = '<div class="jet-form-builder__fields-group checkradio-wrap" data-jfb-sync>';
36
37 if ( ! empty( $this->args['field_options'] ) ) {
38 foreach ( $this->args['field_options'] as $value => $option ) {
39 $html .= $this->render_option( $value, $option );
40 }
41 }
42
43 if ( ! empty( $this->args['custom_option'] ) ) {
44 $html .= $this->render_custom_option();
45 }
46
47 $html .= '</div>';
48 $this->reset_attributes();
49
50 return $html;
51 }
52
53 public function render_option( $value, $option ): string {
54 $default = (string) ( $this->args['default'] ?? false );
55
56 if ( is_array( $option ) ) {
57 $val = $option['value'] ?? $value;
58 $label = $option['label'] ?? $val;
59 } else {
60 $val = $value;
61 $label = $option;
62 }
63
64 $html = '<div class="jet-form-builder__field-wrap radio-wrap checkradio-wrap">';
65
66 $item = sprintf(
67 '<label class="jet-form-builder__field-label for-radio">
68 <input %1$s %2$s><span>%3$s</span></label>',
69 Builder_Helper::attrs(
70 array(
71 array( 'type', 'radio' ),
72 array( 'name', esc_attr( $this->block_type->get_field_name() ) ),
73 array( 'value', esc_attr( $val ) ),
74 array( 'data-field-name', esc_attr( $this->args['name'] ) ),
75 array( 'checked', ( (string) $val ) === $default ? 'checked' : '' ),
76 array(
77 'data-calculate',
78 ( is_array( $option ) && isset( $option['calculate'] ) && '' !== $option['calculate'] )
79 ? esc_attr( $option['calculate'] )
80 : '',
81 ),
82 )
83 ),
84 $this->get_attributes_string_save(),
85 wp_kses_post( $label )
86 );
87
88 /**
89 * @since 3.1.0
90 */
91 $html .= apply_filters(
92 'jet-form-builder/render/radio-field/option',
93 $item,
94 $val,
95 $option,
96 $this
97 );
98
99 $html .= '</div>';
100
101 return $html;
102 }
103
104 protected function render_custom_option(): string {
105 $html = '<div class="jet-form-builder__field-wrap radio-wrap checkradio-wrap custom-option">';
106 $class_name = $this->args['class_name'] ?? '';
107
108 $item = sprintf(
109 '<label class="jet-form-builder__field-label for-radio">
110 <input %1$s value=""><span>%2$s</span></label>',
111 Builder_Helper::attrs(
112 array(
113 array( 'type', 'radio' ),
114 array( 'name', esc_attr( $this->block_type->get_field_name() ) ),
115 array( 'data-field-name', esc_attr( $this->args['name'] ) ),
116 array( 'data-custom', 1 ),
117 array(
118 'class',
119 'jet-form-builder__field radio-field checkradio-field' . ( $class_name ? " {$class_name}" : '' ),
120 ),
121 )
122 ),
123 sprintf(
124 '<input %s>',
125 Builder_Helper::attrs(
126 array(
127 array( 'type', 'text' ),
128 array( 'name', esc_attr( $this->block_type->get_field_name() ) ),
129 array( 'data-field-name', esc_attr( $this->args['name'] ) ),
130 array( 'class', 'jet-form-builder__field text-field' ),
131 array( 'disabled', 'disabled' ),
132 array( 'required', $this->block_type->get_required_val() ),
133 )
134 )
135 )
136 );
137
138 /**
139 * @since 3.2.0
140 */
141 $html .= apply_filters(
142 'jet-form-builder/render/radio-field/custom-option',
143 $item,
144 $this
145 );
146
147 $html .= '</div>';
148
149 return $html;
150 }
151
152 /**
153 * @return string
154 * @see \Jet_Form_Builder\Blocks\Render\Calculated_Field_Render::get_fields_label_tag
155 */
156 protected function get_fields_label_tag(): string {
157 return 'div';
158 }
159
160 }
161