3 namespace MediaWiki\Widget
;
5 use OOUI\MultilineTextInputWidget
;
8 * Abstract base class for widgets to select multiple users, titles,
11 * @copyright 2017 MediaWiki Widgets Team and others; see AUTHORS.txt
14 abstract class TagMultiselectWidget
extends \OOUI\Widget
{
16 protected $selectedArray = [];
17 protected $inputName = null;
18 protected $inputPlaceholder = null;
19 protected $tagLimit = null;
22 * @param array $config Configuration options
23 * - array $config['default'] Array of items to use as preset data
24 * - array $config['name'] Name attribute (used in forms)
25 * - array $config['placeholder'] Placeholder message for input
26 * - array $config['input'] Config options for the input widget
27 * - number $config['tagLimit'] Maximum number of selected items
29 public function __construct( array $config = [] ) {
30 parent
::__construct( $config );
33 if ( isset( $config['default'] ) ) {
34 $this->selectedArray
= $config['default'];
36 if ( isset( $config['name'] ) ) {
37 $this->inputName
= $config['name'];
39 if ( isset( $config['placeholder'] ) ) {
40 $this->inputPlaceholder
= $config['placeholder'];
42 if ( isset( $config['input'] ) ) {
43 $this->input
= $config['input'];
47 if ( isset( $config['tagLimit'] ) ) {
48 $this->tagLimit
= $config['tagLimit'];
51 $textarea = new MultilineTextInputWidget( array_merge( [
52 'name' => $this->inputName
,
53 'value' => implode( "\n", $this->selectedArray
),
56 'mw-widgets-tagMultiselectWidget-multilineTextInputWidget'
60 $pending = new PendingTextInputWidget();
62 $this->appendContent( $textarea, $pending );
63 $this->addClasses( [ 'mw-widgets-tagMultiselectWidget' ] );
66 public function getConfig( &$config ) {
67 if ( $this->selectedArray
!== null ) {
68 $config['selected'] = $this->selectedArray
;
70 if ( $this->inputName
!== null ) {
71 $config['name'] = $this->inputName
;
73 if ( $this->inputPlaceholder
!== null ) {
74 $config['placeholder'] = $this->inputPlaceholder
;
76 if ( $this->input
!== null ) {
77 $config['input'] = $this->input
;
79 if ( $this->tagLimit
!== null ) {
80 $config['tagLimit'] = $this->tagLimit
;
83 $config['$overlay'] = true;
84 return parent
::getConfig( $config );