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