1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
<?php
namespace OOUI;
/**
* Generic widget for buttons.
*/
class SelectFileInputWidget extends InputWidget {
use RequiredElement;
/* Static Properties */
/** @var string[]|null */
protected $accept;
/** @var bool */
protected $multiple;
/** @var string|null */
protected $placeholder;
/** @var array|null */
protected $button;
/** @var string|null */
protected $icon;
/**
* @param array $config Configuration options
* - string[]|null $config['accept'] MIME types to accept. null accepts all types.
* (default: null)
* - bool $config['multiple'] Allow multiple files to be selected. (default: false)
* - string $config['placeholder'] Text to display when no file is selected.
* - array $config['button'] Config to pass to select file button.
* - string $config['icon'] Icon to show next to file info
* and show a preview (for performance).
*/
public function __construct( array $config = [] ) {
// Parent constructor
parent::__construct( $config );
// Properties
$this->accept = $config['accept'] ?? null;
$this->multiple = $config['multiple'] ?? false;
$this->placeholder = $config['placeholder'] ?? null;
$this->button = $config['button'] ?? null;
$this->icon = $config['icon'] ?? null;
// Traits
$this->initializeRequiredElement(
array_merge( [ 'indicatorElement' => null ], $config )
);
// Initialization
$this->addClasses( [ 'oo-ui-selectFileInputWidget' ] );
$this->input->setAttributes( [
'type' => 'file'
] );
if ( $this->multiple ) {
$this->input->setAttributes( [
'multiple' => ''
] );
}
if ( $this->accept ) {
$this->input->setAttributes( [
'accept' => implode( ',', $this->accept )
] );
}
}
/** @inheritDoc */
public function getConfig( &$config ) {
if ( $this->accept !== null ) {
$config['accept'] = $this->accept;
}
if ( $this->multiple !== null ) {
$config['multiple'] = $this->multiple;
}
if ( $this->placeholder !== null ) {
$config['placeholder'] = $this->placeholder;
}
if ( $this->button !== null ) {
$config['button'] = $this->button;
}
if ( $this->icon !== null ) {
$config['icon'] = $this->icon;
}
return parent::getConfig( $config );
}
}
|