resourceloader: Remove comment about XmlJsCode wrapper
[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 * - bool $config['required'] Configuration for whether the widget is a required input.
28 */
29 public function __construct( array $config = [] ) {
30 // Configuration initialization
31 $config = array_merge(
32 [
33 'textinput' => [],
34 'dropdowninput' => [],
35 'or' => false,
36 'required' => false,
37 ],
38 $config
39 );
40
41 if ( isset( $config['disabled'] ) && $config['disabled'] ) {
42 $config['textinput']['disabled'] = true;
43 $config['dropdowninput']['disabled'] = true;
44 }
45
46 $config['textinput']['required'] = $config['or'] ? false : $config['required'];
47 $config['dropdowninput']['required'] = $config['required'];
48
49 parent::__construct( $config );
50
51 // Properties
52 $this->config = $config;
53 $this->textinput = new TextInputWidget( $config['textinput'] );
54 $this->dropdowninput = new DropdownInputWidget( $config['dropdowninput'] );
55
56 // Initialization
57 $this
58 ->addClasses( [ 'mw-widget-selectWithInputWidget' ] )
59 ->appendContent( $this->dropdowninput, $this->textinput );
60 }
61
62 protected function getJavaScriptClassName() {
63 return 'mw.widgets.SelectWithInputWidget';
64 }
65
66 public function getConfig( &$config ) {
67 $config['textinput'] = $this->config['textinput'];
68 $config['dropdowninput'] = $this->config['dropdowninput'];
69 $config['dropdowninput']['dropdown']['$overlay'] = true;
70 $config['or'] = $this->config['or'];
71 $config['required'] = $this->config['required'];
72 return parent::getConfig( $config );
73 }
74 }