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