← All changes
|
includes/Frontend/Form/View/Theme/Fields/FileUploadField.php
+114
-76
2.0
→
3.3.1
View file →
| @@ -1,109 +1,147 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Frontend\Form\View\Theme\Fields; |
| 4 | 4 | |
| 5 | -class FileUploadField { | |
| 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 | +use BitCode\BitForm\Core\Util\FrontendHelpers; | |
| 6 | + | |
| 7 | +class FileUploadField | |
| 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); | |
| 8 | 12 | $input = self::field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 9 | 13 | return $inputWrapper->wrapper($input); |
| 10 | 14 | } |
| 11 | 15 | |
| 12 | - private static function field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) { | |
| 13 | - $fh = new FieldHelpers($field, $rowID, $form_atomic_Cls_map); | |
| 16 | + private static function field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) | |
| 17 | + { | |
| 18 | + $fh = new ClassicFieldHelpers($field, $rowID, $form_atomic_Cls_map); | |
| 14 | 19 | $prefixIcn = $fh->icon('prefixIcn', 'pre-i'); |
| 15 | 20 | $suffixIcn = $fh->icon('suffixIcn', 'suf-i'); |
| 16 | 21 | $name = $fh->name(); |
| 17 | 22 | $req = $fh->required(); |
| 23 | + $ariaDescribedBy = $fh->ariaDescribedBy(); | |
| 24 | + $ariaRequired = $fh->ariaRequired(); | |
| 18 | 25 | $readonlyCls = isset($field->readonly) ? 'readonly' : ''; |
| 19 | 26 | $disabledCls = isset($field->disabled) ? 'disabled' : ''; |
| 20 | 27 | $btnTxt = isset($field->btnTxt) ? $field->btnTxt : ''; |
| 21 | 28 | $showSelectStatus = ''; |
| 22 | 29 | $maxSizeSection = ''; |
| 23 | - $maxSize = isset($field->config->maxSize) ? $field->config->maxSize : ''; | |
| 24 | - $sizeUnit = isset($field->config->sizeUnit) ? $field->config->sizeUnit : ''; | |
| 30 | + $multiple = ''; | |
| 31 | + $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds; | |
| 32 | + $contentCount = count($bfFrontendFormIds); | |
| 25 | 33 | |
| 34 | + if ($fh->property_exists_nested($field, 'config->multiple', true)) { | |
| 35 | + $multiple = 'multiple'; | |
| 36 | + } | |
| 37 | + | |
| 26 | 38 | if ($fh->property_exists_nested($field, 'config->showSelectStatus', true)) { |
| 27 | - $showSelectStatus = <<<SHOWSELSTATUS | |
| 28 | - <div | |
| 29 | - class="{$fh->getAtomicCls('file-select-status')} {$fh->getCustomClasses('file-select-status')}" | |
| 30 | - {$fh->getCustomAttributes('file-select-status')} | |
| 31 | - > | |
| 32 | - No Choosen File | |
| 33 | - </div> | |
| 34 | -SHOWSELSTATUS; | |
| 39 | + $showSelectStatus = sprintf( | |
| 40 | + '<div | |
| 41 | + %1$s | |
| 42 | + class="%2$s %3$s" | |
| 43 | + > | |
| 44 | + No Choosen File | |
| 45 | + </div>', | |
| 46 | + $fh->getCustomAttributes('file-select-status'), | |
| 47 | + $fh->getAtomicCls('file-select-status'), | |
| 48 | + $fh->getCustomClasses('file-select-status') | |
| 49 | + ); | |
| 35 | 50 | } |
| 36 | 51 | |
| 37 | - if ( | |
| 38 | - $fh->property_exists_nested($field, 'config->allowMaxSize', true) | |
| 39 | - && $fh->property_exists_nested($field, 'config->showMaxSize', true) | |
| 40 | - && $fh->property_exists_nested($field, 'config->maxSize') | |
| 41 | - && 0 !== $field->config->maxSize | |
| 42 | - ) { | |
| 43 | - $maxSizeLbl = $fh->property_exists_nested($field, 'config->maxSizeLabel', '', 1) ? $field->config->maxSizeLabel : "(Max {$maxSize} ${sizeUnit})"; | |
| 44 | - $maxSizeSection = <<<MAXSIZE | |
| 45 | - <small | |
| 46 | - class="{$fh->getAtomicCls('max-size-lbl')} {$fh->getCustomClasses('max-size-lbl')}" | |
| 47 | - {$fh->getCustomAttributes('max-size-lbl')} | |
| 48 | - > | |
| 49 | - $maxSizeLbl | |
| 50 | - </small> | |
| 51 | -MAXSIZE; | |
| 52 | - } | |
| 52 | + $maxSizeSection = apply_filters('bitform_file_max_size_section', '', $field, $fh); | |
| 53 | 53 | |
| 54 | - return <<<FILEUPLOADFIELD | |
| 55 | - <div | |
| 56 | - class="{$fh->getAtomicCls('file-up-container')} {$fh->getCustomClasses('file-up-container')}" | |
| 57 | - {$fh->getCustomAttributes('file-up-container')} | |
| 58 | - > | |
| 59 | - <div | |
| 60 | - class="{$fh->getAtomicCls('file-up-wrpr')} {$fh->getCustomClasses('file-up-wrpr')} {$readonlyCls} {$disabledCls}" | |
| 61 | - {$fh->getCustomAttributes('file-up-wrpr')} | |
| 54 | + return sprintf( | |
| 55 | + '<div | |
| 56 | + %1$s | |
| 57 | + class="%2$s %3$s" | |
| 62 | 58 | > |
| 63 | 59 | <div |
| 64 | - class="{$fh->getAtomicCls('file-input-wrpr')} {$fh->getCustomClasses('file-input-wrpr')}" | |
| 65 | - {$fh->getCustomAttributes('file-input-wrpr')} | |
| 60 | + %4$s | |
| 61 | + class="%5$s %6$s %7$s %8$s" | |
| 66 | 62 | > |
| 67 | 63 | <div |
| 68 | - class="{$fh->getAtomicCls('btn-wrpr')} {$fh->getCustomClasses('btn-wrpr')}" | |
| 69 | - {$fh->getCustomAttributes('btn-wrpr')} | |
| 64 | + %9$s | |
| 65 | + class="%10$s %11$s" | |
| 70 | 66 | > |
| 71 | - <button | |
| 72 | - type="button" | |
| 73 | - class="{$fh->getAtomicCls('inp-btn')} {$fh->getCustomClasses('inp-btn')}" | |
| 74 | - {$fh->getCustomAttributes('inp-btn')} | |
| 67 | + <div | |
| 68 | + %12$s | |
| 69 | + class="%13$s %14$s" | |
| 75 | 70 | > |
| 76 | - {$prefixIcn} | |
| 77 | - <span | |
| 78 | - class="{$fh->getAtomicCls('btn-txt')} {$fh->getCustomClasses('btn-txt')}" | |
| 79 | - {$fh->getCustomAttributes('btn-txt')} | |
| 71 | + <button | |
| 72 | + %15$s | |
| 73 | + type="button" | |
| 74 | + class="%16$s %17$s" | |
| 80 | 75 | > |
| 81 | - {$btnTxt} | |
| 82 | - </span> | |
| 83 | - {$suffixIcn} | |
| 84 | - </button> | |
| 85 | - {$showSelectStatus} | |
| 86 | - {$maxSizeSection} | |
| 87 | - <input | |
| 88 | - type="file" | |
| 89 | - class="{$fh->getAtomicCls('file-upload-input')} {$fh->getCustomClasses('file-upload-input')}" | |
| 90 | - {$fh->getCustomAttributes('file-upload-input')} | |
| 91 | - id="{$rowID}" | |
| 92 | - {$name} | |
| 93 | - {$req} | |
| 94 | - {$fh->disabled()} | |
| 95 | - {$fh->readonly()} | |
| 96 | - aria-disabled="true" | |
| 97 | - tabindex="-1" | |
| 98 | - /> | |
| 76 | + %18$s | |
| 77 | + <span | |
| 78 | + %19$s | |
| 79 | + class="%20$s %21$s" | |
| 80 | + > | |
| 81 | + %22$s | |
| 82 | + </span> | |
| 83 | + %23$s | |
| 84 | + </button> | |
| 85 | + %24$s | |
| 86 | + %25$s | |
| 87 | + <input | |
| 88 | + %26$s | |
| 89 | + type="file" | |
| 90 | + class="%27$s %28$s" | |
| 91 | + id="%29$s-%30$s" | |
| 92 | + %31$s | |
| 93 | + %32$s | |
| 94 | + %33$s | |
| 95 | + %34$s | |
| 96 | + %35$s | |
| 97 | + aria-disabled="true" | |
| 98 | + tabindex="-1" | |
| 99 | + /> | |
| 100 | + </div> | |
| 101 | + <div | |
| 102 | + %36$s | |
| 103 | + class="err-wrp %37$s" | |
| 104 | + ></div> | |
| 99 | 105 | </div> |
| 100 | - <div | |
| 101 | - class="err-wrp {$fh->getCustomClasses('err-wrp')}" | |
| 102 | - {$fh->getCustomAttributes('err-wrp')} | |
| 103 | - ></div> | |
| 104 | 106 | </div> |
| 105 | - </div> | |
| 106 | - </div> | |
| 107 | -FILEUPLOADFIELD; | |
| 107 | + </div>', | |
| 108 | + $fh->getCustomAttributes('file-up-container'), | |
| 109 | + $fh->getAtomicCls('file-up-container'), | |
| 110 | + $fh->getCustomClasses('file-up-container'), | |
| 111 | + $fh->getCustomAttributes('file-up-wrpr'), | |
| 112 | + $fh->getAtomicCls('file-up-wrpr'), | |
| 113 | + $fh->getCustomClasses('file-up-wrpr'), | |
| 114 | + $readonlyCls, | |
| 115 | + $disabledCls, | |
| 116 | + $fh->getCustomAttributes('file-input-wrpr'), | |
| 117 | + $fh->getAtomicCls('file-input-wrpr'), | |
| 118 | + $fh->getCustomClasses('file-input-wrpr'), | |
| 119 | + $fh->getCustomAttributes('btn-wrpr'), | |
| 120 | + $fh->getAtomicCls('btn-wrpr'), | |
| 121 | + $fh->getCustomClasses('btn-wrpr'), | |
| 122 | + $fh->getCustomAttributes('inp-btn'), | |
| 123 | + $fh->getAtomicCls('inp-btn'), | |
| 124 | + $fh->getCustomClasses('inp-btn'), | |
| 125 | + $prefixIcn, | |
| 126 | + $fh->getCustomAttributes('btn-txt'), | |
| 127 | + $fh->getAtomicCls('btn-txt'), | |
| 128 | + $fh->getCustomClasses('btn-txt'), | |
| 129 | + $fh->kses_post($btnTxt), | |
| 130 | + $suffixIcn, | |
| 131 | + $showSelectStatus, | |
| 132 | + $maxSizeSection, | |
| 133 | + $fh->getCustomAttributes('file-upload-input'), | |
| 134 | + $fh->getAtomicCls('file-upload-input'), | |
| 135 | + $fh->getCustomClasses('file-upload-input'), | |
| 136 | + $rowID, | |
| 137 | + $contentCount, | |
| 138 | + $name, | |
| 139 | + $req, | |
| 140 | + $fh->disabled(), | |
| 141 | + $fh->readonly(), | |
| 142 | + $multiple, | |
| 143 | + $fh->getCustomAttributes('err-wrp'), | |
| 144 | + $fh->getCustomClasses('err-wrp') | |
| 145 | + ); | |
| 108 | 146 | } |
| 109 | 147 | } |