PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.2.1
JetFormBuilder — Dynamic Blocks Form Builder v3.2.1
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 / checkbox-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 wysiwyg-field-render.php 2 years ago
checkbox-field-render.php
181 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 Checkbox_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 'checkbox-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 checkboxes-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']['allow'] ) ) {
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 = $this->args['default'] ?? array();
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 checkboxes-wrap checkradio-wrap">';
70
71 $item = sprintf(
72 '<label class="jet-form-builder__field-label for-checkbox">
73 <input %1$s %2$s><span>%3$s</span></label>',
74 Builder_Helper::attrs(
75 array(
76 array( 'type', 'checkbox' ),
77 array( 'name', esc_attr( $this->block_type->get_field_name() . $this->get_name_suffix() ) ),
78 array( 'value', esc_attr( $val ) ),
79 array( 'data-field-name', esc_attr( $this->args['name'] ) ),
80 array( 'checked', in_array( (string) $val, $default, true ) ? '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 $html .= apply_filters(
94 'jet-form-builder/render/checkbox-field/option',
95 $item,
96 $val,
97 $option,
98 $this
99 );
100
101 $html .= '</div>';
102
103 return $html;
104 }
105
106 protected function render_custom_option(): string {
107 $html = '<div class="jet-form-builder__field-wrap checkboxes-wrap checkradio-wrap custom-option">';
108 $class_name = $this->args['class_name'] ?? '';
109
110 $name = esc_attr( $this->block_type->get_field_name() . $this->get_name_suffix() );
111 $checkbox = sprintf(
112 '<input %1$s value="">',
113 Builder_Helper::attrs(
114 array(
115 array( 'type', 'checkbox' ),
116 array( 'checked', 'checked' ),
117 array( 'data-field-name', esc_attr( $this->args['name'] ) ),
118 array( 'data-custom', 1 ),
119 array(
120 'class',
121 'jet-form-builder__field checkboxes-field checkradio-field' . (
122 $class_name ? " {$class_name}" : ''
123 ),
124 ),
125 )
126 )
127 );
128
129 $input = sprintf(
130 '<input %s>',
131 Builder_Helper::attrs(
132 array(
133 array( 'type', 'text' ),
134 array( 'name', $name ),
135 array( 'data-field-name', esc_attr( $this->args['name'] ) ),
136 array( 'class', 'jet-form-builder__field text-field' ),
137 )
138 )
139 );
140
141 /**
142 * @since 3.2.0
143 */
144 $item_template = apply_filters(
145 'jet-form-builder/render/checkbox-field/custom-option',
146 sprintf(
147 '<label class="jet-form-builder__field-label for-checkbox">%1$s<span>%2$s</span><label>',
148 $checkbox,
149 $input
150 )
151 );
152
153 $custom_label = $this->args['custom_option']['label'] ?? '';
154 $custom_label = $custom_label ?: __( '+ Add New', 'jet-form-builder' );
155
156 $button = sprintf(
157 '<button type="button" class="add-custom-option">%1$s<template>%2$s</template></button>',
158 $custom_label,
159 $html . $item_template . '</div>'
160 );
161
162 $html .= $button . '</div>';
163
164 return $html;
165 }
166
167 public function get_name_suffix(): string {
168 return count( $this->args['field_options'] ) > 1 ? '[]' : '';
169 }
170
171 /**
172 * @see \Jet_Form_Builder\Blocks\Render\Calculated_Field_Render::get_fields_label_tag
173 *
174 * @return string
175 */
176 protected function get_fields_label_tag(): string {
177 return 'div';
178 }
179
180 }
181