summaryrefslogtreecommitdiff
path: root/www/wiki/includes/widget/SelectWithInputWidget.php
blob: 5ceed4c4086edb132beb2f87e304b77f19840b02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

namespace MediaWiki\Widget;

use OOUI\DropdownInputWidget;
use OOUI\TextInputWidget;

/**
 * Select and input widget.
 *
 * @copyright 2011-2017 MediaWiki Widgets Team and others; see AUTHORS.txt
 * @license MIT
 */
class SelectWithInputWidget extends \OOUI\Widget {

	protected $textinput = null;
	protected $dropdowninput = null;

	/**
	 * A version of the SelectWithInputWidget, with `or` set to true.
	 *
	 * @param array $config Configuration options
	 *   - array $config['textinput'] Configuration for the TextInputWidget
	 *   - array $config['dropdowninput'] Configuration for the DropdownInputWidget
	 *   - bool $config['or'] Configuration for whether the widget is dropdown AND input
	 *                              or dropdown OR input
	 */
	public function __construct( array $config = [] ) {
		// Configuration initialization
		$config = array_merge(
			[
				'textinput' => [],
				'dropdowninput' => [],
				'or' => false
			],
			$config
		);

		parent::__construct( $config );

		// Properties
		$this->config = $config;
		$this->textinput = new TextInputWidget( $config['textinput'] );
		$this->dropdowninput = new DropdownInputWidget( $config['dropdowninput'] );

		// Initialization
		$this
			->addClasses( [ 'mw-widget-selectWithInputWidget' ] )
			->appendContent( $this->dropdowninput, $this->textinput );
	}

	protected function getJavaScriptClassName() {
		return 'mw.widgets.SelectWithInputWidget';
	}

	public function getConfig( &$config ) {
		$config['textinput'] = $this->config['textinput'];
		$config['dropdowninput'] = $this->config['dropdowninput'];
		$config['dropdowninput']['dropdown']['$overlay'] = true;
		$config['or'] = $this->config['or'];
		return parent::getConfig( $config );
	}
}