PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.13
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.13
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
bit-form / includes / Frontend / Form / View / Theme / Fields / ImageSelectField.php

ImageSelectField.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.21.13, at includes/Frontend/Form/View/Theme/Fields/ImageSelectField.php

222 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Frontend\Form\View\Theme\Fields;
4
5 use BitCode\BitForm\Core\Util\FrontendHelpers;
6
7 class ImageSelectField
8 {
9 public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null)
10 {
11 $inputWrapper = new ClassicInputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
12 $input = self::field($field, $rowID, $form_atomic_Cls_map, $value);
13 return $inputWrapper->wrapper($input);
14 }
15
16 private static function field($field, $rowID, $form_atomic_Cls_map, $value)
17 {
18 $fieldHelpers = new ClassicFieldHelpers($field, $rowID, $form_atomic_Cls_map);
19
20 $name = $fieldHelpers->name();
21 $req = $fieldHelpers->required();
22
23 $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds;
24 $contentCount = count($bfFrontendFormIds);
25
26 $imageOption = '';
27 if (!empty($field->val)) {
28 $value = $field->val;
29 }
30 if (!empty($value) && false !== strpos($value, BITFORMS_BF_SEPARATOR)) {
31 $defaultValues = explode(BITFORMS_BF_SEPARATOR, $value);
32 } else {
33 $defaultValues = isset($value) ? explode(',', $value) : [];
34 }
35
36 if (isset($field->opt)) {
37 $checkedImg = $field->tickImgSrc;
38 foreach ($field->opt as $key => $opt) {
39 $val = isset($opt->val) ? $opt->val : $opt->lbl;
40 $img = $opt->img;
41 $lbl = $fieldHelpers->renderHTMR($opt->lbl);
42 $checked = '';
43 $inpType = $field->inpType;
44 $imgAlt = $fieldHelpers->esc_html($lbl);
45 $disabled = '';
46
47 if ($fieldHelpers->property_exists_nested($opt, 'check', true)) {
48 $checked = 'checked';
49 } elseif (in_array($val, $defaultValues)) {
50 $checked = 'checked';
51 }
52
53 if ($fieldHelpers->property_exists_nested($field, 'valid->disabled', true)
54 || $fieldHelpers->property_exists_nested($opt, 'disabled', true)) {
55 $disabled = 'disabled';
56 }
57
58 if (isset($field->mx) && !empty($field->valid->disableOnMax) && !$checked && ((int) $field->mx <= count($defaultValues))) {
59 $disabled = 'disabled';
60 }
61
62 $optLblHide = '';
63
64 if (!$field->optLblHide) {
65 $optLblHide = sprintf(
66 '<div
67 class="%1$s %2$s"
68 %3$s
69 >
70 <span
71 class="%4$s %5$s"
72 %6$s
73 >
74 %7$s
75 </span>
76 </div>',
77 $fieldHelpers->getAtomicCls('tc'),
78 $fieldHelpers->getCustomClasses('tc'),
79 $fieldHelpers->getCustomAttributes('tc'),
80 $fieldHelpers->getAtomicCls('img-title'),
81 $fieldHelpers->getCustomClasses('img-title'),
82 $fieldHelpers->getCustomAttributes('img-title'),
83 $fieldHelpers->kses_post($lbl)
84 );
85 }
86
87 // Input element
88 $inputHtml = sprintf(
89 '<input
90 class="%1$s %2$s"
91 type="%3$s"
92 id="%4$s-%5$s-img-wrp-%6$s"
93 %7$s
94 value="%8$s"
95 %9$s
96 %10$s
97 %11$s
98 %12$s
99 />',
100 $fieldHelpers->getAtomicCls('img-inp'),
101 $fieldHelpers->getCustomClasses('img-inp'),
102 $inpType,
103 $rowID,
104 $contentCount,
105 $key,
106 $name,
107 $fieldHelpers->esc_attr($val),
108 $checked,
109 $req,
110 $disabled,
111 $fieldHelpers->getCustomAttributes('img-inp')
112 );
113
114 // Check box with tick image
115 $checkBoxHtml = sprintf(
116 '<span
117 class="%1$s %2$s"
118 %3$s
119 >
120 <img
121 src="%4$s"
122 alt=""
123 class="%5$s %6$s"
124 %7$s
125 />
126 </span>',
127 $fieldHelpers->getAtomicCls('check-box'),
128 $fieldHelpers->getCustomClasses('check-box'),
129 $fieldHelpers->getCustomAttributes('check-box'),
130 $checkedImg,
131 $fieldHelpers->getAtomicCls('check-img'),
132 $fieldHelpers->getCustomClasses('check-img'),
133 $fieldHelpers->getCustomAttributes('check-img')
134 );
135
136 // Image card wrapper with selectable image
137 $imgCardHtml = sprintf(
138 '<span
139 class="%1$s %2$s"
140 %3$s
141 >
142 <img
143 src="%4$s"
144 alt="%5$s"
145 aria-label="%5$s"
146 class="%6$s %7$s"
147 %8$s
148 />
149 %9$s
150 </span>',
151 $fieldHelpers->getAtomicCls('img-card-wrp'),
152 $fieldHelpers->getCustomClasses('img-card-wrp'),
153 $fieldHelpers->getCustomAttributes('img-card-wrp'),
154 $img,
155 $imgAlt,
156 $fieldHelpers->getAtomicCls('select-img'),
157 $fieldHelpers->getCustomClasses('select-img'),
158 $fieldHelpers->getCustomAttributes('select-img'),
159 $optLblHide
160 );
161
162 // Label wrapper
163 $labelHtml = sprintf(
164 '<label
165 for="%1$s-%2$s-img-wrp-%3$s"
166 class="%4$s %5$s"
167 %6$s
168 >
169 %7$s
170 %8$s
171 </label>',
172 $rowID,
173 $contentCount,
174 $key,
175 $fieldHelpers->getAtomicCls('img-wrp'),
176 $fieldHelpers->getCustomClasses('img-wrp'),
177 $fieldHelpers->getCustomAttributes('img-wrp'),
178 $checkBoxHtml,
179 $imgCardHtml
180 );
181
182 // Full option item
183 $imageOption .= sprintf(
184 '<div
185 class="%1$s %2$s"
186 %3$s
187 >
188 %4$s
189 %5$s
190 </div>',
191 $fieldHelpers->getAtomicCls('inp-opt'),
192 $fieldHelpers->getCustomClasses('inp-opt'),
193 $fieldHelpers->getCustomAttributes('inp-opt'),
194 $inputHtml,
195 $labelHtml
196 );
197 }
198 }
199
200 return sprintf(
201 '<div
202 class="%1$s %2$s"
203 %3$s
204 >
205 <div
206 class="%4$s %5$s"
207 %6$s
208 >
209 %7$s
210 </div>
211 </div>',
212 $fieldHelpers->getAtomicCls('inp-fld-wrp'),
213 $fieldHelpers->getCustomClasses('inp-fld-wrp'),
214 $fieldHelpers->getCustomAttributes('inp-fld-wrp'),
215 $fieldHelpers->getAtomicCls('ic'),
216 $fieldHelpers->getCustomClasses('ic'),
217 $fieldHelpers->getCustomAttributes('ic'),
218 $imageOption
219 );
220 }
221 }
222