2017-03-22 10:16:24 +00:00
|
|
|
<?php
|
2017-12-28 15:17:33 +00:00
|
|
|
|
2017-03-22 10:16:24 +00:00
|
|
|
namespace MediaWiki\Widget;
|
|
|
|
|
|
2017-12-28 15:17:33 +00:00
|
|
|
use OOUI\DropdownInputWidget;
|
|
|
|
|
use OOUI\TextInputWidget;
|
2024-01-02 18:31:56 +00:00
|
|
|
use OOUI\Widget;
|
2017-03-22 10:16:24 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Select and input widget.
|
2017-12-28 15:17:33 +00:00
|
|
|
*
|
2018-01-24 19:59:05 +00:00
|
|
|
* @copyright 2011-2017 MediaWiki Widgets Team and others; see AUTHORS.txt
|
2017-12-28 15:17:33 +00:00
|
|
|
* @license MIT
|
2017-03-22 10:16:24 +00:00
|
|
|
*/
|
2024-01-02 18:31:56 +00:00
|
|
|
class SelectWithInputWidget extends Widget {
|
2019-09-10 12:05:14 +00:00
|
|
|
/** @var array */
|
|
|
|
|
protected $config;
|
|
|
|
|
/** @var TextInputWidget */
|
|
|
|
|
protected $textinput;
|
|
|
|
|
/** @var DropdownInputWidget */
|
|
|
|
|
protected $dropdowninput;
|
2017-03-22 10:16:24 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A version of the SelectWithInputWidget, with `or` set to true.
|
|
|
|
|
*
|
|
|
|
|
* @param array $config Configuration options
|
2018-01-07 10:38:43 +00:00
|
|
|
* - 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
|
2019-02-11 14:59:36 +00:00
|
|
|
* or dropdown OR input
|
2019-07-22 22:53:14 +00:00
|
|
|
* - bool $config['required'] Configuration for whether the widget is a required input.
|
2017-03-22 10:16:24 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct( array $config = [] ) {
|
|
|
|
|
// Configuration initialization
|
|
|
|
|
$config = array_merge(
|
|
|
|
|
[
|
|
|
|
|
'textinput' => [],
|
|
|
|
|
'dropdowninput' => [],
|
2019-07-22 22:53:14 +00:00
|
|
|
'or' => false,
|
|
|
|
|
'required' => false,
|
2017-03-22 10:16:24 +00:00
|
|
|
],
|
|
|
|
|
$config
|
|
|
|
|
);
|
|
|
|
|
|
2019-02-11 14:59:36 +00:00
|
|
|
if ( isset( $config['disabled'] ) && $config['disabled'] ) {
|
2018-07-25 05:29:03 +00:00
|
|
|
$config['textinput']['disabled'] = true;
|
|
|
|
|
$config['dropdowninput']['disabled'] = true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 22:53:14 +00:00
|
|
|
$config['textinput']['required'] = $config['or'] ? false : $config['required'];
|
|
|
|
|
$config['dropdowninput']['required'] = $config['required'];
|
|
|
|
|
|
2017-03-22 10:16:24 +00:00
|
|
|
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'];
|
2018-01-02 22:25:01 +00:00
|
|
|
$config['dropdowninput']['dropdown']['$overlay'] = true;
|
2017-03-22 10:16:24 +00:00
|
|
|
$config['or'] = $this->config['or'];
|
2019-07-22 22:53:14 +00:00
|
|
|
$config['required'] = $this->config['required'];
|
2017-03-22 10:16:24 +00:00
|
|
|
return parent::getConfig( $config );
|
|
|
|
|
}
|
|
|
|
|
}
|