Merge "Add .pipeline/ with dev image variant"
[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 /** @var array */
16 protected $config;
17 /** @var TextInputWidget */
18 protected $textinput;
19 /** @var DropdownInputWidget */
20 protected $dropdowninput;
21
22 /**
23 * A version of the SelectWithInputWidget, with `or` set to true.
24 *
25 * @param array $config Configuration options
26 * - array $config['textinput'] Configuration for the TextInputWidget
27 * - array $config['dropdowninput'] Configuration for the DropdownInputWidget
28 * - bool $config['or'] Configuration for whether the widget is dropdown AND input
29 * or dropdown OR input
30 * - bool $config['required'] Configuration for whether the widget is a required input.
31 */
32 public function __construct( array $config = [] ) {
33 // Configuration initialization
34 $config = array_merge(
35 [
36 'textinput' => [],
37 'dropdowninput' => [],
38 'or' => false,
39 'required' => false,
40 ],
41 $config
42 );
43
44 if ( isset( $config['disabled'] ) && $config['disabled'] ) {
45 $config['textinput']['disabled'] = true;
46 $config['dropdowninput']['disabled'] = true;
47 }
48
49 $config['textinput']['required'] = $config['or'] ? false : $config['required'];
50 $config['dropdowninput']['required'] = $config['required'];
51
52 parent::__construct( $config );
53
54 // Properties
55 $this->config = $config;
56 $this->textinput = new TextInputWidget( $config['textinput'] );
57 $this->dropdowninput = new DropdownInputWidget( $config['dropdowninput'] );
58
59 // Initialization
60 $this
61 ->addClasses( [ 'mw-widget-selectWithInputWidget' ] )
62 ->appendContent( $this->dropdowninput, $this->textinput );
63 }
64
65 protected function getJavaScriptClassName() {
66 return 'mw.widgets.SelectWithInputWidget';
67 }
68
69 public function getConfig( &$config ) {
70 $config['textinput'] = $this->config['textinput'];
71 $config['dropdowninput'] = $this->config['dropdowninput'];
72 $config['dropdowninput']['dropdown']['$overlay'] = true;
73 $config['or'] = $this->config['or'];
74 $config['required'] = $this->config['required'];
75 return parent::getConfig( $config );
76 }
77 }