PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
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 3.3.1, at includes/Frontend/Form/View/Theme/Fields/ImageSelectField.php

235 lines 6.7 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 aria-hidden="true"
124 class="%5$s %6$s"
125 %7$s
126 />
127 </span>',
128 $fieldHelpers->getAtomicCls('check-box'),
129 $fieldHelpers->getCustomClasses('check-box'),
130 $fieldHelpers->getCustomAttributes('check-box'),
131 $checkedImg,
132 $fieldHelpers->getAtomicCls('check-img'),
133 $fieldHelpers->getCustomClasses('check-img'),
134 $fieldHelpers->getCustomAttributes('check-img')
135 );
136
137 // Image card wrapper with selectable image
138 $imgCardHtml = sprintf(
139 '<span
140 class="%1$s %2$s"
141 %3$s
142 >
143 <img
144 src="%4$s"
145 alt="%5$s"
146 aria-label="%5$s"
147 class="%6$s %7$s"
148 %8$s
149 />
150 %9$s
151 </span>',
152 $fieldHelpers->getAtomicCls('img-card-wrp'),
153 $fieldHelpers->getCustomClasses('img-card-wrp'),
154 $fieldHelpers->getCustomAttributes('img-card-wrp'),
155 $img,
156 $imgAlt,
157 $fieldHelpers->getAtomicCls('select-img'),
158 $fieldHelpers->getCustomClasses('select-img'),
159 $fieldHelpers->getCustomAttributes('select-img'),
160 $optLblHide
161 );
162
163 // Label wrapper
164 $labelHtml = sprintf(
165 '<label
166 for="%1$s-%2$s-img-wrp-%3$s"
167 class="%4$s %5$s"
168 %6$s
169 >
170 %7$s
171 %8$s
172 </label>',
173 $rowID,
174 $contentCount,
175 $key,
176 $fieldHelpers->getAtomicCls('img-wrp'),
177 $fieldHelpers->getCustomClasses('img-wrp'),
178 $fieldHelpers->getCustomAttributes('img-wrp'),
179 $checkBoxHtml,
180 $imgCardHtml
181 );
182
183 // Full option item
184 $imageOption .= sprintf(
185 '<div
186 class="%1$s %2$s"
187 %3$s
188 >
189 %4$s
190 %5$s
191 </div>',
192 $fieldHelpers->getAtomicCls('inp-opt'),
193 $fieldHelpers->getCustomClasses('inp-opt'),
194 $fieldHelpers->getCustomAttributes('inp-opt'),
195 $inputHtml,
196 $labelHtml
197 );
198 }
199 }
200
201 $labelId = $fieldHelpers->getLabelId();
202 $ariaDescribedBy = $fieldHelpers->ariaDescribedBy();
203 $ariaRequired = $fieldHelpers->ariaRequired();
204 $roleType = 'radio' === $field->inpType ? 'radiogroup' : 'group';
205 return sprintf(
206 '<div
207 class="%1$s %2$s"
208 %3$s
209 >
210 <div
211 class="%4$s %5$s"
212 %6$s
213 role="%7$s"
214 aria-labelledby="%8$s"
215 %9$s
216 %10$s
217 >
218 %11$s
219 </div>
220 </div>',
221 $fieldHelpers->getAtomicCls('inp-fld-wrp'),
222 $fieldHelpers->getCustomClasses('inp-fld-wrp'),
223 $fieldHelpers->getCustomAttributes('inp-fld-wrp'),
224 $fieldHelpers->getAtomicCls('ic'),
225 $fieldHelpers->getCustomClasses('ic'),
226 $fieldHelpers->getCustomAttributes('ic'),
227 $roleType,
228 $labelId,
229 $ariaDescribedBy,
230 $ariaRequired,
231 $imageOption
232 );
233 }
234 }
235