]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/widget/SelectWithInputWidget.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.git] / includes / widget / SelectWithInputWidget.php
1 <?php
2 /**
3  * MediaWiki Widgets – SelectWithInputWidget class.
4  *
5  * @copyright 2011-2017 MediaWiki Widgets Team and others; see AUTHORS.txt
6  * @license The MIT License (MIT); see LICENSE.txt
7  */
8 namespace MediaWiki\Widget;
9
10 use \OOUI\TextInputWidget;
11 use \OOUI\DropdownInputWidget;
12
13 /**
14  * Select and input widget.
15  */
16 class SelectWithInputWidget extends \OOUI\Widget {
17
18         protected $textinput = null;
19         protected $dropdowninput = null;
20
21         /**
22          * A version of the SelectWithInputWidget, with `or` set to true.
23          *
24          * @param array $config Configuration options
25          * @param array $config['textinput'] Configuration for the TextInputWidget
26          * @param array $config['dropdowninput'] Configuration for the DropdownInputWidget
27          * @param bool $config['or'] Configuration for whether the widget is dropdown AND input
28          *                              or dropdown OR input
29          */
30         public function __construct( array $config = [] ) {
31                 // Configuration initialization
32                 $config = array_merge(
33                         [
34                                 'textinput' => [],
35                                 'dropdowninput' => [],
36                                 'or' => false
37                         ],
38                         $config
39                 );
40
41                 // Parent constructor
42                 parent::__construct( $config );
43
44                 // Properties
45                 $this->config = $config;
46                 $this->textinput = new TextInputWidget( $config['textinput'] );
47                 $this->dropdowninput = new DropdownInputWidget( $config['dropdowninput'] );
48
49                 // Initialization
50                 $this
51                         ->addClasses( [ 'mw-widget-selectWithInputWidget' ] )
52                         ->appendContent( $this->dropdowninput, $this->textinput );
53         }
54
55         protected function getJavaScriptClassName() {
56                 return 'mw.widgets.SelectWithInputWidget';
57         }
58
59         public function getConfig( &$config ) {
60                 $config['textinput'] = $this->config['textinput'];
61                 $config['dropdowninput'] = $this->config['dropdowninput'];
62                 $config['or'] = $this->config['or'];
63                 return parent::getConfig( $config );
64         }
65 }