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