| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Widget; |
| 4 |
|
| 5 |
use InvalidArgumentException; |
| 6 |
use OOUI\InputWidget; |
| 7 |
use OOUI\Tag; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class DateTimeInputWidget extends InputWidget { |
| 16 |
|
| 17 |
|
| 18 |
protected $type = null; |
| 19 |
|
| 20 |
protected $min = null; |
| 21 |
|
| 22 |
protected $max = null; |
| 23 |
|
| 24 |
protected $clearable = null; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public function __construct( array $config = [] ) { |
| 34 |
|
| 35 |
if ( !isset( $config['type'] ) ) { |
| 36 |
throw new InvalidArgumentException( '$config[\'type\'] must be specified' ); |
| 37 |
} |
| 38 |
$this->type = $config['type']; |
| 39 |
|
| 40 |
parent::__construct( $config ); |
| 41 |
|
| 42 |
|
| 43 |
if ( isset( $config['min'] ) ) { |
| 44 |
$this->min = $config['min']; |
| 45 |
} |
| 46 |
if ( isset( $config['max'] ) ) { |
| 47 |
$this->max = $config['max']; |
| 48 |
} |
| 49 |
if ( isset( $config['clearable'] ) ) { |
| 50 |
$this->clearable = $config['clearable']; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
$this->addClasses( [ 'mw-widgets-datetime-dateTimeInputWidget' ] ); |
| 55 |
} |
| 56 |
|
| 57 |
protected function getJavaScriptClassName() { |
| 58 |
return 'mw.widgets.datetime.DateTimeInputWidget'; |
| 59 |
} |
| 60 |
|
| 61 |
public function getConfig( &$config ) { |
| 62 |
$config['type'] = $this->type; |
| 63 |
if ( $this->min !== null ) { |
| 64 |
$config['min'] = $this->min; |
| 65 |
} |
| 66 |
if ( $this->max !== null ) { |
| 67 |
$config['max'] = $this->max; |
| 68 |
} |
| 69 |
if ( $this->clearable !== null ) { |
| 70 |
$config['clearable'] = $this->clearable; |
| 71 |
} |
| 72 |
return parent::getConfig( $config ); |
| 73 |
} |
| 74 |
|
| 75 |
protected function getInputElement( $config ) { |
| 76 |
return ( new Tag( 'input' ) )->setAttributes( [ 'type' => $this->type ] ); |
| 77 |
} |
| 78 |
} |