wiki.techinc.nl/includes/widget/UsersMultiselectWidget.php
James D. Forrester fb4e63ba3f Update OOjs UI to v0.23.5
Release notes:
 https://phabricator.wikimedia.org/diffusion/GOJU/browse/master/History.md;v0.23.5

Also, replace uses of `OOUI\TextInputWidget( [ 'multiline' => true ] )`
with `OOUI\MultilineTextInputWidget()` to avoid deprecation warnings
(which cause unit tests to fail).

Depends-on: I990b14982ffb72fe981040d02c7023d13f721aaa
Change-Id: If8312c60e1547a6177f5491011badb6576f54b21
2017-10-12 14:45:39 -07:00

67 lines
1.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* MediaWiki Widgets UsersMultiselectWidget class.
*
* @copyright 2017 MediaWiki Widgets Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
namespace MediaWiki\Widget;
use \OOUI\MultilineTextInputWidget;
/**
* Widget to select multiple users.
*/
class UsersMultiselectWidget extends \OOUI\Widget {
protected $usersArray = [];
protected $inputName = null;
protected $inputPlaceholder = null;
/**
* @param array $config Configuration options
* @param array $config['users'] Array of usernames to use as preset data
* @param array $config['placeholder'] Placeholder message for input
* @param array $config['name'] Name attribute (used in forms)
*/
public function __construct( array $config = [] ) {
parent::__construct( $config );
// Properties
if ( isset( $config['default'] ) ) {
$this->usersArray = $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->usersArray ),
'rows' => 25,
] );
$this->prependContent( $textarea );
}
protected function getJavaScriptClassName() {
return 'mw.widgets.UsersMultiselectWidget';
}
public function getConfig( &$config ) {
if ( $this->usersArray !== null ) {
$config['selected'] = $this->usersArray;
}
if ( $this->inputName !== null ) {
$config['name'] = $this->inputName;
}
if ( $this->inputPlaceholder !== null ) {
$config['placeholder'] = $this->inputPlaceholder;
}
return parent::getConfig( $config );
}
}