Add the widget in both PHP and JS for OOUI, and into HTMLForm definitions. In JS, the widget uses the engine from mw.widgets.TitleWidget with the async support from OO.ui.mixin.RequestManager. The PHP version provides a textarea, like UsersMultiselectWidget.php which is then infused if JS is available. Also, add highlightSearchQuery option for TitleWidget to allow for not highlighting the partial search query the user typed in, if the UI requires it. This option (highlighting partial result) is already optional in the TitleOptionWidget, so this config exposes that optionality in the TitleWidget widget for its menu children. Notes: HTMLTitlesMultiselectField is a duplication of HTMLUsersMultiselectField except for: - The configuration variable changed to 'titles' (from 'users') - OOUI modules were adjusted for the TitlesMultiselectWidget - The PHP version instantiates a MediaWiki\Widget\TitlesMultiselectWidget TitlesMultiselectWidget is a duplication of UsersMultiselectWidget except for: - $usersArray was renamed to $titlesArray - getJavascriptClassName returns the correct js class for mw.widgets.TitlesMultiselectWidget for infusion. Bug: T197109 Depends-On: I675316dddf272fd0d6172ecad3882160752bf780 Change-Id: Ie96947a35f70b76731e16ae5b85de815dfa4a8ce
67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Widget;
|
|
|
|
use OOUI\MultilineTextInputWidget;
|
|
|
|
/**
|
|
* Widget to select multiple titles.
|
|
*
|
|
* @copyright 2017 MediaWiki Widgets Team and others; see AUTHORS.txt
|
|
* @license MIT
|
|
*/
|
|
class TitlesMultiselectWidget extends \OOUI\Widget {
|
|
|
|
protected $titlesArray = [];
|
|
protected $inputName = null;
|
|
protected $inputPlaceholder = null;
|
|
|
|
/**
|
|
* @param array $config Configuration options
|
|
* - array $config['titles'] Array of titles to use as preset data
|
|
* - array $config['placeholder'] Placeholder message for input
|
|
* - array $config['name'] Name attribute (used in forms)
|
|
*/
|
|
public function __construct( array $config = [] ) {
|
|
parent::__construct( $config );
|
|
|
|
// Properties
|
|
if ( isset( $config['default'] ) ) {
|
|
$this->titlesArray = $config['default'];
|
|
}
|
|
if ( isset( $config['name'] ) ) {
|
|
$this->inputName = $config['name'];
|
|
}
|
|
if ( isset( $config['placeholder'] ) ) {
|
|
$this->inputPlaceholder = $config['placeholder'];
|
|
}
|
|
|
|
$textarea = new MultilineTextInputWidget( [
|
|
'name' => $this->inputName,
|
|
'value' => implode( "\n", $this->titlesArray ),
|
|
'rows' => 10,
|
|
] );
|
|
$this->appendContent( $textarea );
|
|
$this->addClasses( [ 'mw-widgets-titlesMultiselectWidget' ] );
|
|
}
|
|
|
|
protected function getJavaScriptClassName() {
|
|
return 'mw.widgets.TitlesMultiselectWidget';
|
|
}
|
|
|
|
public function getConfig( &$config ) {
|
|
if ( $this->titlesArray !== null ) {
|
|
$config['selected'] = $this->titlesArray;
|
|
}
|
|
if ( $this->inputName !== null ) {
|
|
$config['name'] = $this->inputName;
|
|
}
|
|
if ( $this->inputPlaceholder !== null ) {
|
|
$config['placeholder'] = $this->inputPlaceholder;
|
|
}
|
|
|
|
$config['$overlay'] = true;
|
|
return parent::getConfig( $config );
|
|
}
|
|
|
|
}
|