3 * MediaWiki Widgets – DateTimeInputWidget class.
5 * @copyright 2016 MediaWiki Widgets Team and others; see AUTHORS.txt
6 * @license The MIT License (MIT); see LICENSE.txt
8 namespace MediaWiki\Widget
;
13 * Date-time input widget.
15 class DateTimeInputWidget
extends \OOUI\InputWidget
{
17 protected $type = null;
18 protected $min = null;
19 protected $max = null;
20 protected $clearable = null;
23 * @param array $config Configuration options
24 * - string $config['type'] 'date', 'time', or 'datetime'
25 * - string $config['min'] Minimum date, time, or datetime
26 * - string $config['max'] Maximum date, time, or datetime
27 * - bool $config['clearable'] Whether to provide for blanking the value.
29 public function __construct( array $config = [] ) {
30 // We need $this->type set before calling the parent constructor
31 if ( isset( $config['type'] ) ) {
32 $this->type
= $config['type'];
34 throw new \
InvalidArgumentException( '$config[\'type\'] must be specified' );
37 parent
::__construct( $config );
39 // Properties, which are ignored in PHP and just shipped back to JS
40 if ( isset( $config['min'] ) ) {
41 $this->min
= $config['min'];
43 if ( isset( $config['max'] ) ) {
44 $this->max
= $config['max'];
46 if ( isset( $config['clearable'] ) ) {
47 $this->clearable
= $config['clearable'];
51 $this->addClasses( [ 'mw-widgets-datetime-dateTimeInputWidget' ] );
54 protected function getJavaScriptClassName() {
55 return 'mw.widgets.datetime.DateTimeInputWidget';
58 public function getConfig( &$config ) {
59 $config['type'] = $this->type
;
60 if ( $this->min
!== null ) {
61 $config['min'] = $this->min
;
63 if ( $this->max
!== null ) {
64 $config['max'] = $this->max
;
66 if ( $this->clearable
!== null ) {
67 $config['clearable'] = $this->clearable
;
69 return parent
::getConfig( $config );
72 protected function getInputElement( $config ) {
73 return ( new Tag( 'input' ) )->setAttributes( [ 'type' => $this->type
] );