Merge ".mailmap: Correct two contributor names"
[mediawiki.git] / includes / widget / SelectWithInputWidget.php
blobf75237d2641b333e8ffb3a474dd6934869abffd9
1 <?php
3 namespace MediaWiki\Widget;
5 use OOUI\DropdownInputWidget;
6 use OOUI\TextInputWidget;
7 use OOUI\Widget;
9 /**
10 * Select and input widget.
12 * @copyright 2011-2017 MediaWiki Widgets Team and others; see AUTHORS.txt
13 * @license MIT
15 class SelectWithInputWidget extends Widget {
16 /** @var array */
17 protected $config;
18 /** @var TextInputWidget */
19 protected $textinput;
20 /** @var DropdownInputWidget */
21 protected $dropdowninput;
23 /**
24 * A version of the SelectWithInputWidget, with `or` set to true.
26 * @param array $config Configuration options
27 * - array $config['textinput'] Configuration for the TextInputWidget
28 * - array $config['dropdowninput'] Configuration for the DropdownInputWidget
29 * - bool $config['or'] Configuration for whether the widget is dropdown AND input
30 * or dropdown OR input
31 * - bool $config['required'] Configuration for whether the widget is a required input.
33 public function __construct( array $config = [] ) {
34 // Configuration initialization
35 $config = array_merge(
37 'textinput' => [],
38 'dropdowninput' => [],
39 'or' => false,
40 'required' => false,
42 $config
45 if ( isset( $config['disabled'] ) && $config['disabled'] ) {
46 $config['textinput']['disabled'] = true;
47 $config['dropdowninput']['disabled'] = true;
50 $config['textinput']['required'] = $config['or'] ? false : $config['required'];
51 $config['dropdowninput']['required'] = $config['required'];
53 parent::__construct( $config );
55 // Properties
56 $this->config = $config;
57 $this->textinput = new TextInputWidget( $config['textinput'] );
58 $this->dropdowninput = new DropdownInputWidget( $config['dropdowninput'] );
60 // Initialization
61 $this
62 ->addClasses( [ 'mw-widget-selectWithInputWidget' ] )
63 ->appendContent( $this->dropdowninput, $this->textinput );
66 protected function getJavaScriptClassName() {
67 return 'mw.widgets.SelectWithInputWidget';
70 public function getConfig( &$config ) {
71 $config['textinput'] = $this->config['textinput'];
72 $config['dropdowninput'] = $this->config['dropdowninput'];
73 $config['dropdowninput']['dropdown']['$overlay'] = true;
74 $config['or'] = $this->config['or'];
75 $config['required'] = $this->config['required'];
76 return parent::getConfig( $config );