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