Merge "Improve docs for Title::getInternalURL/getCanonicalURL"
[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 if ( isset( $config['disabled'] ) && $config['disabled'] ) {
40 $config['textinput']['disabled'] = true;
41 $config['dropdowninput']['disabled'] = true;
42 }
43
44 parent::__construct( $config );
45
46 // Properties
47 $this->config = $config;
48 $this->textinput = new TextInputWidget( $config['textinput'] );
49 $this->dropdowninput = new DropdownInputWidget( $config['dropdowninput'] );
50
51 // Initialization
52 $this
53 ->addClasses( [ 'mw-widget-selectWithInputWidget' ] )
54 ->appendContent( $this->dropdowninput, $this->textinput );
55 }
56
57 protected function getJavaScriptClassName() {
58 return 'mw.widgets.SelectWithInputWidget';
59 }
60
61 public function getConfig( &$config ) {
62 $config['textinput'] = $this->config['textinput'];
63 $config['dropdowninput'] = $this->config['dropdowninput'];
64 $config['dropdowninput']['dropdown']['$overlay'] = true;
65 $config['or'] = $this->config['or'];
66 return parent::getConfig( $config );
67 }
68 }