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 /** @var string|null */
19 /** @var string|null */
20 protected $inputPlaceholder;
27 * @param array $config Configuration options
28 * - array $config['default'] Array of items to use as preset data
29 * - string $config['name'] Name attribute (used in forms)
30 * - string $config['placeholder'] Placeholder message for input
31 * - array $config['input'] Config options for the input widget
32 * - int $config['tagLimit'] Maximum number of selected items
34 public function __construct( array $config = [] ) {
35 parent
::__construct( $config );
38 $this->selectedArray
= $config['default'] ??
[];
39 $this->inputName
= $config['name'] ??
null;
40 $this->inputPlaceholder
= $config['placeholder'] ??
null;
41 $this->input
= $config['input'] ??
[];
42 $this->tagLimit
= $config['tagLimit'] ??
null;
44 $textarea = new MultilineTextInputWidget( array_merge( [
45 'name' => $this->inputName
,
46 'value' => implode( "\n", $this->selectedArray
),
49 'mw-widgets-tagMultiselectWidget-multilineTextInputWidget'
53 $pending = new PendingTextInputWidget();
55 $this->appendContent( $textarea, $pending );
56 $this->addClasses( [ 'mw-widgets-tagMultiselectWidget' ] );
59 public function getConfig( &$config ) {
60 if ( $this->selectedArray
!== null ) {
61 $config['selected'] = $this->selectedArray
;
63 if ( $this->inputName
!== null ) {
64 $config['name'] = $this->inputName
;
66 if ( $this->inputPlaceholder
!== null ) {
67 $config['placeholder'] = $this->inputPlaceholder
;
69 if ( $this->input
!== null ) {
70 $config['input'] = $this->input
;
72 if ( $this->tagLimit
!== null ) {
73 $config['tagLimit'] = $this->tagLimit
;
76 $config['$overlay'] = true;
77 return parent
::getConfig( $config );