3 namespace MediaWiki\Widget
;
8 * Date-time input widget.
10 * @copyright 2016 MediaWiki Widgets Team and others; see AUTHORS.txt
13 class DateTimeInputWidget
extends \OOUI\InputWidget
{
15 protected $type = null;
16 protected $min = null;
17 protected $max = null;
18 protected $clearable = null;
21 * @param array $config Configuration options
22 * - string $config['type'] 'date', 'time', or 'datetime'
23 * - string $config['min'] Minimum date, time, or datetime
24 * - string $config['max'] Maximum date, time, or datetime
25 * - bool $config['clearable'] Whether to provide for blanking the value.
27 public function __construct( array $config = [] ) {
28 // We need $this->type set before calling the parent constructor
29 if ( isset( $config['type'] ) ) {
30 $this->type
= $config['type'];
32 throw new \
InvalidArgumentException( '$config[\'type\'] must be specified' );
35 parent
::__construct( $config );
37 // Properties, which are ignored in PHP and just shipped back to JS
38 if ( isset( $config['min'] ) ) {
39 $this->min
= $config['min'];
41 if ( isset( $config['max'] ) ) {
42 $this->max
= $config['max'];
44 if ( isset( $config['clearable'] ) ) {
45 $this->clearable
= $config['clearable'];
49 $this->addClasses( [ 'mw-widgets-datetime-dateTimeInputWidget' ] );
52 protected function getJavaScriptClassName() {
53 return 'mw.widgets.datetime.DateTimeInputWidget';
56 public function getConfig( &$config ) {
57 $config['type'] = $this->type
;
58 if ( $this->min
!== null ) {
59 $config['min'] = $this->min
;
61 if ( $this->max
!== null ) {
62 $config['max'] = $this->max
;
64 if ( $this->clearable
!== null ) {
65 $config['clearable'] = $this->clearable
;
67 return parent
::getConfig( $config );
70 protected function getInputElement( $config ) {
71 return ( new Tag( 'input' ) )->setAttributes( [ 'type' => $this->type
] );