← All changes
|
includes/Frontend/Form/View/Theme/Fields/RadioBoxField.php
+175
-81
2.10.0
→
V3.3.2
View file →
| @@ -21,12 +21,12 @@ | ||
| 21 | 21 | $value = ''; |
| 22 | 22 | $radioBoxOptions = ''; |
| 23 | 23 | $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds; |
| 24 | 24 | $contentCount = count($bfFrontendFormIds); |
| 25 | - if (property_exists($field, 'opt') && count($field->opt) > 0) { | |
| 26 | - $defaultValue = !empty($field->val) ? $field->val : ''; | |
| 25 | + if (is_object($field) && property_exists($field, 'opt') && is_countable($field->opt) && count($field->opt) > 0) { | |
| 26 | + $defaultValue = isset($field->val) ? $field->val : ''; | |
| 27 | 27 | foreach ($field->opt as $key => $opt) { |
| 28 | - $value = !empty($opt->val) ? $opt->val : $opt->lbl; | |
| 28 | + $value = isset($opt->val) ? $opt->val : ($opt->lbl ?? ''); | |
| 29 | 29 | $check = ''; |
| 30 | 30 | $req = ''; |
| 31 | 31 | $lbl = $fieldHelpers->renderHTMR($opt->lbl); |
| 32 | 32 | $disabled = ''; |
| @@ -44,112 +44,206 @@ | ||
| 44 | 44 | || $fieldHelpers->property_exists_nested($opt, 'disabled', true)) { |
| 45 | 45 | $disabled = "disabled='disabled'"; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - $radioBoxOptions .= <<<RADIOBOXOPTIONS | |
| 49 | - <div | |
| 50 | - {$fieldHelpers->getCustomAttributes('cw')} | |
| 51 | - class="{$fieldHelpers->getAtomicCls('cw')} {$fieldHelpers->getCustomClasses('cw')}" | |
| 48 | + $radioBoxOptions .= sprintf( | |
| 49 | + '<div | |
| 50 | + %1$s | |
| 51 | + class="%2$s %3$s" | |
| 52 | 52 | > |
| 53 | 53 | <input |
| 54 | - {$fieldHelpers->getCustomAttributes('ci')} | |
| 55 | - id="{$rowID}-{$contentCount}-chk-{$key}" | |
| 54 | + %4$s | |
| 55 | + id="%5$s-%6$s-chk-%7$s" | |
| 56 | 56 | type="radio" |
| 57 | - class="{$fieldHelpers->getAtomicCls('ci')} {$fieldHelpers->getCustomClasses('ci')}" | |
| 58 | - value="{$fieldHelpers->esc_attr($value)}" | |
| 59 | - {$check} | |
| 60 | - {$name} | |
| 61 | - {$req} | |
| 62 | - {$disabled} | |
| 57 | + class="%8$s %9$s" | |
| 58 | + value="%10$s" | |
| 59 | + %11$s | |
| 60 | + %12$s | |
| 61 | + %13$s | |
| 62 | + %14$s | |
| 63 | 63 | /> |
| 64 | 64 | <label |
| 65 | - {$fieldHelpers->getCustomAttributes('cl')} | |
| 65 | + %15$s | |
| 66 | 66 | data-cl |
| 67 | - for="{$rowID}-{$contentCount}-chk-{$key}" | |
| 68 | - class="{$fieldHelpers->getAtomicCls('cl')} {$fieldHelpers->getCustomClasses('cl')}" | |
| 67 | + for="%5$s-%6$s-chk-%7$s" | |
| 68 | + class="%16$s %17$s" | |
| 69 | 69 | > |
| 70 | 70 | <span |
| 71 | - {$fieldHelpers->getCustomAttributes('bx')} | |
| 71 | + %18$s | |
| 72 | 72 | data-bx |
| 73 | - class="{$fieldHelpers->getAtomicCls('bx')} {$fieldHelpers->getCustomClasses('bx')}" | |
| 73 | + class="%19$s %20$s" | |
| 74 | 74 | > |
| 75 | - <svg width="12" height="10" viewBox="0 0 12 10" class="{$fieldHelpers->getAtomicCls('svgwrp')} {$fieldHelpers->getCustomClasses('svgwrp')}"> | |
| 76 | - <use data-ck-icn href=#{$rowID}-ck-svg class="{$fieldHelpers->getAtomicCls('ck-icn')} {$fieldHelpers->getCustomClasses('ck-icn')}" /> | |
| 75 | + <svg | |
| 76 | + width="12" | |
| 77 | + height="10" | |
| 78 | + viewBox="0 0 12 10" | |
| 79 | + class="%21$s %22$s" | |
| 80 | + aria-hidden="true" | |
| 81 | + > | |
| 82 | + <use | |
| 83 | + data-ck-icn | |
| 84 | + href=#%5$s-ck-svg | |
| 85 | + class="%23$s %24$s" | |
| 86 | + /> | |
| 77 | 87 | </svg> |
| 78 | 88 | </span> |
| 79 | 89 | <span |
| 80 | - {$fieldHelpers->getCustomAttributes('ct')} | |
| 81 | - class="{$fieldHelpers->getAtomicCls('ct')} {$fieldHelpers->getCustomClasses('ct')}" | |
| 90 | + %25$s | |
| 91 | + class="%26$s %27$s" | |
| 82 | 92 | > |
| 83 | - {$fieldHelpers->kses_post($lbl)} | |
| 93 | + %28$s | |
| 84 | 94 | </span> |
| 85 | 95 | </label> |
| 86 | - </div> | |
| 87 | -RADIOBOXOPTIONS; | |
| 96 | + </div>', | |
| 97 | + $fieldHelpers->getCustomAttributes('cw'), | |
| 98 | + $fieldHelpers->getAtomicCls('cw'), | |
| 99 | + $fieldHelpers->getCustomClasses('cw'), | |
| 100 | + $fieldHelpers->getCustomAttributes('ci'), | |
| 101 | + $rowID, | |
| 102 | + $contentCount, | |
| 103 | + $key, | |
| 104 | + $fieldHelpers->getAtomicCls('ci'), | |
| 105 | + $fieldHelpers->getCustomClasses('ci'), | |
| 106 | + $fieldHelpers->esc_attr($value), | |
| 107 | + $check, | |
| 108 | + $name, | |
| 109 | + $req, | |
| 110 | + $disabled, | |
| 111 | + $fieldHelpers->getCustomAttributes('cl'), | |
| 112 | + $fieldHelpers->getAtomicCls('cl'), | |
| 113 | + $fieldHelpers->getCustomClasses('cl'), | |
| 114 | + $fieldHelpers->getCustomAttributes('bx'), | |
| 115 | + $fieldHelpers->getAtomicCls('bx'), | |
| 116 | + $fieldHelpers->getCustomClasses('bx'), | |
| 117 | + $fieldHelpers->getAtomicCls('svgwrp'), | |
| 118 | + $fieldHelpers->getCustomClasses('svgwrp'), | |
| 119 | + $fieldHelpers->getAtomicCls('ck-icn'), | |
| 120 | + $fieldHelpers->getCustomClasses('ck-icn'), | |
| 121 | + $fieldHelpers->getCustomAttributes('ct'), | |
| 122 | + $fieldHelpers->getAtomicCls('ct'), | |
| 123 | + $fieldHelpers->getCustomClasses('ct'), | |
| 124 | + $fieldHelpers->kses_post($lbl) | |
| 125 | + ); | |
| 88 | 126 | } |
| 89 | 127 | } |
| 90 | 128 | |
| 91 | 129 | //Other Option |
| 92 | - $optCount = property_exists($field, 'opt') ? count($field->opt) : 0; | |
| 93 | - $inputPh = isset($field->otherInpPh) ? $field->otherInpPh : 'Other...'; | |
| 130 | + $otherOptLbl = !empty($field->otherOptLbl) ? $field->otherOptLbl : __('Other...', 'bit-form'); | |
| 131 | + $optCount = isset($field->opt) && is_countable($field->opt) ? count($field->opt) : 0; | |
| 132 | + $inputPh = isset($field->otherInpPh) ? $field->otherInpPh : $otherOptLbl; | |
| 94 | 133 | $inpReq = isset($field->valid->otherOptReq) ? ($field->valid->otherOptReq ? 'required' : '') : ''; |
| 95 | 134 | if (property_exists($field, 'addOtherOpt') && $field->addOtherOpt) { |
| 96 | - $radioBoxOptions .= <<<RADIOBOXOPTIONS | |
| 97 | - <div | |
| 98 | - {$fieldHelpers->getCustomAttributes('cw')} | |
| 99 | - class="{$fieldHelpers->getAtomicCls('cw')} {$fieldHelpers->getCustomClasses('cw')}" | |
| 135 | + $check = $check ?? ''; | |
| 136 | + $radioBoxOptions .= sprintf( | |
| 137 | + ' | |
| 138 | + <div | |
| 139 | + %1$s | |
| 140 | + class="%2$s %3$s" | |
| 100 | 141 | > |
| 101 | - <input | |
| 102 | - {$fieldHelpers->getCustomAttributes('ci')} | |
| 103 | - id="{$rowID}-{$contentCount}-chk-{$optCount}" | |
| 104 | - data-oopt="{$rowID}" | |
| 105 | - type="radio" | |
| 106 | - class="{$fieldHelpers->getAtomicCls('ci')} {$fieldHelpers->getCustomClasses('ci')}" | |
| 107 | - value="" | |
| 108 | - {$check} | |
| 109 | - {$name} | |
| 110 | - /> | |
| 111 | - <label | |
| 112 | - {$fieldHelpers->getCustomAttributes('cl')} | |
| 113 | - data-cl | |
| 114 | - for="{$rowID}-{$contentCount}-chk-{$optCount}" | |
| 115 | - class="{$fieldHelpers->getAtomicCls('cl')} {$fieldHelpers->getCustomClasses('cl')}" | |
| 116 | - > | |
| 117 | - <span | |
| 118 | - {$fieldHelpers->getCustomAttributes('rdo')} | |
| 119 | - data-bx | |
| 120 | - class="{$fieldHelpers->getAtomicCls('bx')} {$fieldHelpers->getAtomicCls('rdo')} {$fieldHelpers->getCustomClasses('rdo')}" | |
| 121 | - > | |
| 122 | - <svg width="12" height="10" viewBox="0 0 12 10" class="{$fieldHelpers->getAtomicCls('svgwrp')} {$fieldHelpers->getCustomClasses('svgwrp')}"> | |
| 123 | - <use data-ck-icn href=#{$rowID}-ck-svg class="{$fieldHelpers->getAtomicCls('ck-icn')} {$fieldHelpers->getCustomClasses('ck-icn')}" /> | |
| 124 | - </svg> | |
| 125 | - </span> | |
| 126 | - <span | |
| 127 | - {$fieldHelpers->getCustomAttributes('ct')} | |
| 128 | - class="{$fieldHelpers->getAtomicCls('ct')} {$fieldHelpers->getCustomClasses('ct')}" | |
| 129 | - > | |
| 130 | - Other.. | |
| 131 | - </span> | |
| 132 | - </label> | |
| 133 | - <div data-oinp-wrp class="{$fieldHelpers->getAtomicCls('other-inp-wrp')}"> | |
| 134 | 142 | <input |
| 135 | - data-bf-other-inp="{$rowID}-chk-{$optCount}" | |
| 136 | - type="text" | |
| 137 | - class="{$fieldHelpers->getAtomicCls('other-inp')}" | |
| 138 | - {$inpReq} | |
| 139 | - placeholder="{$fieldHelpers->esc_attr($inputPh)}" | |
| 143 | + %4$s | |
| 144 | + id="%5$s-%6$s-chk-%7$s" | |
| 145 | + data-oopt="%5$s" | |
| 146 | + type="radio" | |
| 147 | + class="%8$s %9$s" | |
| 148 | + value="" | |
| 149 | + %10$s | |
| 150 | + %11$s | |
| 151 | + /> | |
| 152 | + <label | |
| 153 | + %12$s | |
| 154 | + data-cl | |
| 155 | + for="%5$s-%6$s-chk-%7$s" | |
| 156 | + class="%13$s %14$s" | |
| 140 | 157 | > |
| 141 | - </div> | |
| 142 | - </div> | |
| 143 | -RADIOBOXOPTIONS; | |
| 158 | + <span | |
| 159 | + %15$s | |
| 160 | + data-bx | |
| 161 | + class="%16$s %17$s %18$s" | |
| 162 | + > | |
| 163 | + <svg | |
| 164 | + width="12" | |
| 165 | + height="10" | |
| 166 | + viewBox="0 0 12 10" | |
| 167 | + class="%19$s %20$s" | |
| 168 | + > | |
| 169 | + <use | |
| 170 | + data-ck-icn | |
| 171 | + href=#%5$s-ck-svg | |
| 172 | + class="%21$s %22$s" | |
| 173 | + /> | |
| 174 | + </svg> | |
| 175 | + </span> | |
| 176 | + <span | |
| 177 | + %23$s | |
| 178 | + class="%24$s %25$s" | |
| 179 | + > | |
| 180 | + %26$s | |
| 181 | + </span> | |
| 182 | + </label> | |
| 183 | + <div data-oinp-wrp class="%27$s"> | |
| 184 | + <input | |
| 185 | + data-bf-other-inp="%5$s-chk-%7$s" | |
| 186 | + type="text" | |
| 187 | + class="%28$s" | |
| 188 | + %29$s | |
| 189 | + placeholder="%30$s" | |
| 190 | + > | |
| 191 | + </div> | |
| 192 | + </div>', | |
| 193 | + $fieldHelpers->getCustomAttributes('cw'), | |
| 194 | + $fieldHelpers->getAtomicCls('cw'), | |
| 195 | + $fieldHelpers->getCustomClasses('cw'), | |
| 196 | + $fieldHelpers->getCustomAttributes('ci'), | |
| 197 | + $rowID, | |
| 198 | + $contentCount, | |
| 199 | + $optCount, | |
| 200 | + $fieldHelpers->getAtomicCls('ci'), | |
| 201 | + $fieldHelpers->getCustomClasses('ci'), | |
| 202 | + $check, | |
| 203 | + $name, | |
| 204 | + $fieldHelpers->getCustomAttributes('cl'), | |
| 205 | + $fieldHelpers->getAtomicCls('cl'), | |
| 206 | + $fieldHelpers->getCustomClasses('cl'), | |
| 207 | + $fieldHelpers->getCustomAttributes('rdo'), | |
| 208 | + $fieldHelpers->getAtomicCls('bx'), | |
| 209 | + $fieldHelpers->getAtomicCls('rdo'), | |
| 210 | + $fieldHelpers->getCustomClasses('rdo'), | |
| 211 | + $fieldHelpers->getAtomicCls('svgwrp'), | |
| 212 | + $fieldHelpers->getCustomClasses('svgwrp'), | |
| 213 | + $fieldHelpers->getAtomicCls('ck-icn'), | |
| 214 | + $fieldHelpers->getCustomClasses('ck-icn'), | |
| 215 | + $fieldHelpers->getCustomAttributes('ct'), | |
| 216 | + $fieldHelpers->getAtomicCls('ct'), | |
| 217 | + $fieldHelpers->getCustomClasses('ct'), | |
| 218 | + $otherOptLbl, | |
| 219 | + $fieldHelpers->getAtomicCls('other-inp-wrp'), | |
| 220 | + $fieldHelpers->getAtomicCls('other-inp'), | |
| 221 | + $inpReq, | |
| 222 | + $fieldHelpers->esc_attr($inputPh) | |
| 223 | + ); | |
| 144 | 224 | } |
| 145 | 225 | |
| 146 | - return <<<RADIOBOX | |
| 147 | - <div | |
| 148 | - {$fieldHelpers->getCustomAttributes('cc')} | |
| 149 | - class="{$fieldHelpers->getAtomicCls('cc')} {$fieldHelpers->getCustomClasses('cc')}" | |
| 226 | + $labelId = $fieldHelpers->getLabelId(); | |
| 227 | + $ariaDescribedBy = $fieldHelpers->ariaDescribedBy(); | |
| 228 | + $ariaRequired = $fieldHelpers->ariaRequired(); | |
| 229 | + return sprintf( | |
| 230 | + '<div | |
| 231 | + %1$s | |
| 232 | + class="%2$s %3$s" | |
| 233 | + role="radiogroup" | |
| 234 | + aria-labelledby="%4$s" | |
| 235 | + %5$s | |
| 236 | + %6$s | |
| 150 | 237 | > |
| 151 | - {$radioBoxOptions} | |
| 152 | - </div> | |
| 153 | -RADIOBOX; | |
| 238 | + %7$s | |
| 239 | + </div>', | |
| 240 | + $fieldHelpers->getCustomAttributes('cc'), | |
| 241 | + $fieldHelpers->getAtomicCls('cc'), | |
| 242 | + $fieldHelpers->getCustomClasses('cc'), | |
| 243 | + $labelId, | |
| 244 | + $ariaDescribedBy, | |
| 245 | + $ariaRequired, | |
| 246 | + $radioBoxOptions | |
| 247 | + ); | |
| 154 | 248 | } |
| 155 | 249 | } |