MediaWiki master
DateTimeInputWidget.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Widget;
4
5use InvalidArgumentException;
6use OOUI\InputWidget;
7use OOUI\Tag;
8
15class DateTimeInputWidget extends InputWidget {
16
17 protected $type = null;
18 protected $min = null;
19 protected $max = null;
20 protected $clearable = null;
21
29 public function __construct( array $config = [] ) {
30 // We need $this->type set before calling the parent constructor
31 if ( !isset( $config['type'] ) ) {
32 throw new InvalidArgumentException( '$config[\'type\'] must be specified' );
33 }
34 $this->type = $config['type'];
35
36 parent::__construct( $config );
37
38 // Properties, which are ignored in PHP and just shipped back to JS
39 if ( isset( $config['min'] ) ) {
40 $this->min = $config['min'];
41 }
42 if ( isset( $config['max'] ) ) {
43 $this->max = $config['max'];
44 }
45 if ( isset( $config['clearable'] ) ) {
46 $this->clearable = $config['clearable'];
47 }
48
49 // Initialization
50 $this->addClasses( [ 'mw-widgets-datetime-dateTimeInputWidget' ] );
51 }
52
53 protected function getJavaScriptClassName() {
54 return 'mw.widgets.datetime.DateTimeInputWidget';
55 }
56
57 public function getConfig( &$config ) {
58 $config['type'] = $this->type;
59 if ( $this->min !== null ) {
60 $config['min'] = $this->min;
61 }
62 if ( $this->max !== null ) {
63 $config['max'] = $this->max;
64 }
65 if ( $this->clearable !== null ) {
66 $config['clearable'] = $this->clearable;
67 }
68 return parent::getConfig( $config );
69 }
70
71 protected function getInputElement( $config ) {
72 return ( new Tag( 'input' ) )->setAttributes( [ 'type' => $this->type ] );
73 }
74}