PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / trunk
JetFormBuilder — Dynamic Blocks Form Builder vtrunk
3.6.4 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 / select / block-template.php
jetformbuilder / modules / option-field / blocks / select Last commit date
block-render.php 2 years ago block-template.php 1 month ago block-type.php 3 months ago
block-template.php
140 lines
1 <?php
2 /**
3 * input[type="hidden"] template
4 *
5 * @var Block_Render $this
6 * @var array $args
7 */
8
9 use JFB_Modules\Option_Field\Blocks\Select\Block_Render;
10
11 // If this file is called directly, abort.
12 if ( ! defined( 'WPINC' ) ) {
13 die;
14 }
15
16 $this->add_attribute( 'class', 'jet-form-builder__field select-field' );
17 $this->add_attribute( 'class', $args['class_name'] );
18 $this->add_attribute( 'required', $this->block_type->get_required_val() );
19 $this->add_attribute( 'name', $this->block_type->get_field_name() );
20 $this->add_attribute( 'data-field-name', $args['name'] );
21 $this->add_attribute( 'id', $this->block_type->get_field_id( $args ) );
22 $this->add_attribute( 'multiple', $this->block_type->is_multiple() ? 1 : '' );
23 $this->add_attribute(
24 'size',
25 $this->block_type->is_multiple()
26 ? $this->block_type->get_multiple_size()
27 : ''
28 );
29 $this->add_attribute( 'data-jfb-sync' );
30
31 // Add auto-update data attributes if configured
32 if ( ! empty( $args['_jfb_data_attrs'] ) ) {
33 foreach ( $args['_jfb_data_attrs'] as $attr_key => $attr_value ) {
34 $this->add_attribute( $attr_key, $attr_value );
35 }
36 }
37
38 $placeholder = $args['placeholder'] ?? false;
39 $default = $args['default'] ?? false;
40 $has_dynamic_default = false;
41 $is_array_like_string = static function ( $value ) {
42 if ( ! is_string( $value ) ) {
43 return false;
44 }
45
46 $value = trim( $value );
47
48 return '[' === substr( $value, 0, 1 ) && ']' === substr( $value, -1 );
49 };
50
51 if (
52 is_string( $default ) && (
53 jet_form_builder()->regexp->has_macro( $default ) ||
54 $is_array_like_string( $default )
55 )
56 ) {
57 $has_dynamic_default = true;
58 wp_enqueue_script( \Jet_Form_Builder\Blocks\Dynamic_Value::HANDLE );
59 $this->add_attribute( 'data-default-val', $default );
60 } elseif ( is_array( $default ) ) {
61 $normalized_default = array_values( $default );
62 $single_default = $normalized_default[0] ?? '';
63
64 if (
65 1 === count( $normalized_default ) &&
66 is_string( $single_default ) &&
67 '[' === substr( trim( $single_default ), 0, 1 )
68 ) {
69 $dynamic_default = $single_default;
70 } else {
71 $dynamic_default = wp_json_encode( $normalized_default );
72 }
73
74 if (
75 is_string( $dynamic_default ) && (
76 jet_form_builder()->regexp->has_macro( $dynamic_default ) ||
77 $is_array_like_string( $dynamic_default )
78 )
79 ) {
80 $has_dynamic_default = true;
81 wp_enqueue_script( \Jet_Form_Builder\Blocks\Dynamic_Value::HANDLE );
82 $this->add_attribute( 'data-default-val', $dynamic_default );
83 }
84 }
85 ?>
86 <div class="jet-form-builder__field-wrap">
87 <select <?php $this->render_attributes_string(); ?>>
88 <?php
89
90 if ( $placeholder ) {
91 $additional_attrs = ( $args['is_disabled_placeholder'] ?? false ) ? 'disabled' : '';
92
93 if (
94 ! $default ||
95 (
96 $has_dynamic_default &&
97 ! $this->block_type->is_multiple()
98 )
99 ) {
100 $additional_attrs .= ' selected';
101 }
102 // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
103 printf( '<option value="" %1$s>%2$s</option>', $additional_attrs, $placeholder );
104 }
105
106 if ( ! empty( $args['field_options'] ) ) {
107
108 foreach ( $args['field_options'] as $value => $option ) {
109
110 $selected = '';
111 $calc = '';
112
113 if ( is_array( $option ) ) {
114 $val = $option['value'];
115 $label = $option['label'];
116 } else {
117 $val = $value;
118 $label = $option;
119 }
120
121 $this->set_checked_option( $option );
122
123 if ( ! empty( $option['selected'] ) ) {
124 $selected = 'selected="selected"';
125 }
126
127 if ( is_array( $option ) && isset( $option['calculate'] ) ) {
128 $calc = ' data-calculate="' . esc_attr( $option['calculate'] ) . '"';
129 }
130
131 printf( '<option value="%1$s" %3$s%4$s>%2$s</option>', $val, $label, $selected, $calc );
132
133 }
134 }
135
136 ?>
137 </select>
138 </div>
139 <?php // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
140