MediaWiki master
TagMultiselectWidget.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Widget;
4
5use OOUI\MultilineTextInputWidget;
6use OOUI\Widget;
7
15class TagMultiselectWidget extends Widget {
17 protected $selectedArray;
19 protected $inputName;
23 protected $input;
25 protected $tagLimit;
27 protected $allowArbitrary;
29 protected $allowedValues;
30
41 public function __construct( array $config = [] ) {
42 parent::__construct( $config );
43
44 // Properties
45 $this->selectedArray = $config['default'] ?? [];
46 $this->inputName = $config['name'] ?? null;
47 $this->inputPlaceholder = $config['placeholder'] ?? null;
48 $this->input = $config['input'] ?? [];
49 $this->tagLimit = $config['tagLimit'] ?? null;
50 $this->allowArbitrary = $config['allowArbitrary'] ?? false;
51 $this->allowedValues = $config['allowedValues'] ?? null;
52
53 $textarea = new MultilineTextInputWidget( array_merge( [
54 'name' => $this->inputName,
55 'value' => implode( "\n", $this->selectedArray ),
56 'rows' => min( $this->tagLimit, 10 ) ?? 10,
57 'classes' => [
58 'mw-widgets-tagMultiselectWidget-multilineTextInputWidget'
59 ],
60 ], $this->input ) );
61
62 $pending = new PendingTextInputWidget();
63
64 $this->appendContent( $textarea, $pending );
65 $this->addClasses( [ 'mw-widgets-tagMultiselectWidget' ] );
66 }
67
68 public function getConfig( &$config ) {
69 if ( $this->selectedArray !== null ) {
70 $config['selected'] = $this->selectedArray;
71 }
72 if ( $this->inputName !== null ) {
73 $config['name'] = $this->inputName;
74 }
75 if ( $this->inputPlaceholder !== null ) {
76 $config['placeholder'] = $this->inputPlaceholder;
77 }
78 if ( $this->input !== null ) {
79 $config['input'] = $this->input;
80 }
81 if ( $this->tagLimit !== null ) {
82 $config['tagLimit'] = $this->tagLimit;
83 }
84 if ( $this->allowArbitrary !== null ) {
85 $config['allowArbitrary'] = $this->allowArbitrary;
86 }
87 if ( $this->allowedValues !== null ) {
88 $config['allowedValues'] = $this->allowedValues;
89 }
90
91 $config['$overlay'] = true;
92 return parent::getConfig( $config );
93 }
94
95 protected function getJavaScriptClassName() {
96 return 'mw.widgets.TagMultiselectWidget';
97 }
98}
Text input widget that displays pending animation.
Base class for widgets to select multiple users, titles, namespaces, etc.