← All changes
|
includes/Frontend/Form/View/Theme/Fields/ButtonField.php
+85
-33
2.0
→
3.3.1
View file →
| @@ -1,17 +1,44 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Frontend\Form\View\Theme\Fields; |
| 4 | 4 | |
| 5 | -class ButtonField { | |
| 6 | - public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) { | |
| 7 | - $inputWrapper = new InputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); | |
| 5 | +class ButtonField | |
| 6 | +{ | |
| 7 | + public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) | |
| 8 | + { | |
| 9 | + $inputWrapper = new ClassicInputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); | |
| 8 | 10 | $button = self::field($field, $rowID, $form_atomic_Cls_map, $formID); |
| 9 | 11 | return $inputWrapper->wrapper($button, true, true); |
| 10 | 12 | } |
| 11 | 13 | |
| 12 | - private static function field($field, $rowID, $form_atomic_Cls_map, $formID, $error = null, $value = null) { | |
| 13 | - $fieldHelpers = new FieldHelpers($field, $rowID, $form_atomic_Cls_map); | |
| 14 | + private static function getBtnClass($btnTyp) | |
| 15 | + { | |
| 16 | + switch ($btnTyp) { | |
| 17 | + case 'save-draft': | |
| 18 | + return 'bf-trigger-form-abandonment'; | |
| 19 | + case 'next-step': | |
| 20 | + return 'next-step-btn'; | |
| 21 | + case 'previous-step': | |
| 22 | + return 'prev-step-btn'; | |
| 23 | + } | |
| 24 | + return ''; | |
| 25 | + } | |
| 26 | + | |
| 27 | + private static function getBtnTyp($btnTyp) | |
| 28 | + { | |
| 29 | + switch ($btnTyp) { | |
| 30 | + case 'submit': | |
| 31 | + case 'reset': | |
| 32 | + return $btnTyp; | |
| 33 | + default: | |
| 34 | + return 'button'; | |
| 35 | + } | |
| 36 | + } | |
| 37 | + | |
| 38 | + private static function field($field, $rowID, $form_atomic_Cls_map, $formID, $error = null, $value = null) | |
| 39 | + { | |
| 40 | + $fieldHelpers = new ClassicFieldHelpers($field, $rowID, $form_atomic_Cls_map); | |
| 14 | 41 | // $helperTxt = self::helperTxt($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null); |
| 15 | 42 | |
| 16 | 43 | $btnPreIcn = $fieldHelpers->icon('btnPreIcn', 'btn-pre-i'); |
| 17 | 44 | $btnSufIcn = $fieldHelpers->icon('btnSufIcn', 'btn-suf-i'); |
| @@ -17,48 +44,73 @@ | ||
| 17 | 44 | $btnSufIcn = $fieldHelpers->icon('btnSufIcn', 'btn-suf-i'); |
| 18 | 45 | $disabled = $fieldHelpers->disabled(); |
| 19 | 46 | // $name = $field->btnTyp === 'submit' ? 'name="bit-form-submit-btn"' : ''; |
| 20 | 47 | $name = $fieldHelpers->name(); |
| 21 | - $spanner = '<span class="' . $fieldHelpers->getAtomicCls('spanner') . ' d-none"></span>'; | |
| 22 | - $submitSpanner = 'submit' === $field->btnTyp ? $spanner : ''; | |
| 48 | + $btnSpinner = '<span class="bf-spinner d-none" aria-hidden="true"></span>'; | |
| 49 | + $btnClass = self::getBtnClass($field->btnTyp); | |
| 50 | + $btnTyp = self::getBtnTyp($field->btnTyp); | |
| 51 | + $ariaDescribedBy = $fieldHelpers->ariaDescribedBy(); | |
| 23 | 52 | |
| 24 | - return <<<BUTTONFIELD | |
| 25 | - <div class="{$fieldHelpers->getAtomicCls('inp-fld-wrp')} {$fieldHelpers->getCustomClasses('inp-fld-wrp')}" | |
| 26 | - {$fieldHelpers->getCustomAttributes('inp-fld-wrp')} | |
| 53 | + return sprintf( | |
| 54 | + '<div | |
| 55 | + %1$s | |
| 56 | + class="%2$s %3$s" | |
| 27 | 57 | > |
| 28 | 58 | <button |
| 29 | - class="{$fieldHelpers->getAtomicCls('btn')} {$fieldHelpers->getCustomClasses('btn')}" | |
| 30 | - {$fieldHelpers->getCustomAttributes('btn')} | |
| 31 | - type="{$field->btnTyp}" | |
| 32 | - {$name} | |
| 33 | - {$disabled} | |
| 59 | + %4$s | |
| 60 | + class="%5$s %6$s %7$s" | |
| 61 | + type="%8$s" | |
| 62 | + %9$s | |
| 63 | + %10$s | |
| 64 | + %11$s | |
| 34 | 65 | > |
| 35 | - {$btnPreIcn} | |
| 36 | - {$fieldHelpers->renderHTMR($field->txt)} | |
| 37 | - {$btnSufIcn} | |
| 38 | - {$submitSpanner} | |
| 66 | + %12$s | |
| 67 | + %13$s | |
| 68 | + %14$s | |
| 69 | + %15$s | |
| 39 | 70 | </button> |
| 40 | - </div> | |
| 41 | -BUTTONFIELD; | |
| 71 | + </div>', | |
| 72 | + $fieldHelpers->getCustomAttributes('inp-fld-wrp'), // 1 | |
| 73 | + $fieldHelpers->getAtomicCls('inp-fld-wrp'), // 2 | |
| 74 | + $fieldHelpers->getCustomClasses('inp-fld-wrp'), // 3 | |
| 75 | + $fieldHelpers->getCustomAttributes('btn'), // 4 | |
| 76 | + $fieldHelpers->getAtomicCls('btn'), // 5 | |
| 77 | + $fieldHelpers->getCustomClasses('btn'), // 6 | |
| 78 | + $btnClass, // 7 | |
| 79 | + $btnTyp, // 8 | |
| 80 | + $name, // 9 | |
| 81 | + $disabled, // 10 | |
| 82 | + $ariaDescribedBy, // 11 | |
| 83 | + $btnPreIcn, // 12 | |
| 84 | + $fieldHelpers->kses_post($fieldHelpers->renderHTMR($field->txt)), // 13 | |
| 85 | + $btnSufIcn, // 14 | |
| 86 | + $btnSpinner // 15 | |
| 87 | + ); | |
| 42 | 88 | } |
| 43 | 89 | |
| 44 | - private static function helperTxt($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) { | |
| 45 | - $fieldHelpers = new FieldHelpers($field, $rowID, $form_atomic_Cls_map); | |
| 90 | + private static function helperTxt($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) | |
| 91 | + { | |
| 92 | + $fieldHelpers = new ClassicFieldHelpers($field, $rowID, $form_atomic_Cls_map); | |
| 46 | 93 | $hlpPreIcn = $fieldHelpers->icon('hlpPreIcn', 'hlp-txt-pre-i'); |
| 47 | 94 | $hlpSufIcn = $fieldHelpers->icon('hlpSufIcn', 'hlp-txt-suf-i'); |
| 48 | 95 | $hlpTxt = isset($field->helperTxt) ? $fieldHelpers->renderHTMR($field->helperTxt) : ''; |
| 49 | 96 | |
| 50 | - $helperTxt = <<<HELPERTXT | |
| 51 | - <div | |
| 52 | - class="{$fieldHelpers->getAtomicCls('hlp-txt')} {$fieldHelpers->getCustomClasses('hlp-txt')}" | |
| 53 | - {$fieldHelpers->getCustomAttributes('hlp-txt')} | |
| 97 | + $helperTxt = sprintf( | |
| 98 | + '<div | |
| 99 | + %1$s | |
| 100 | + class="%2$s %3$s" | |
| 54 | 101 | > |
| 55 | - {$hlpPreIcn} | |
| 56 | - {$hlpTxt} | |
| 57 | - {$hlpSufIcn} | |
| 58 | - </div> | |
| 59 | - | |
| 60 | -HELPERTXT; | |
| 102 | + %4$s | |
| 103 | + %5$s | |
| 104 | + %6$s | |
| 105 | + </div>', | |
| 106 | + $fieldHelpers->getCustomAttributes('hlp-txt'), | |
| 107 | + $fieldHelpers->getAtomicCls('hlp-txt'), | |
| 108 | + $fieldHelpers->getCustomClasses('hlp-txt'), | |
| 109 | + $hlpPreIcn, | |
| 110 | + $fieldHelpers->kses_post($hlpTxt), | |
| 111 | + $hlpSufIcn | |
| 112 | + ); | |
| 61 | 113 | |
| 62 | 114 | return property_exists($field, 'helperTxt') ? $helperTxt : ''; |
| 63 | 115 | } |
| 64 | 116 | } |