MediaWiki master
TagMultiselectWidget.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Widget;
4
5use OOUI\MultilineTextInputWidget;
6use OOUI\Tag;
7use OOUI\Widget;
8
16class TagMultiselectWidget extends Widget {
18 protected $selectedArray;
20 protected $inputName;
24 protected $input;
26 protected $tagLimit;
28 protected $allowArbitrary;
32 protected $allowedValues;
33
45 public function __construct( array $config = [] ) {
46 parent::__construct( $config );
47
48 // Properties
49 $this->selectedArray = $config['default'] ?? [];
50 $this->inputName = $config['name'] ?? null;
51 $this->inputPlaceholder = $config['placeholder'] ?? null;
52 $this->input = $config['input'] ?? [];
53 $this->tagLimit = $config['tagLimit'] ?? null;
54 $this->allowArbitrary = $config['allowArbitrary'] ?? false;
55 $this->allowReordering = $config['allowReordering'] ?? true;
56 $this->allowedValues = $config['allowedValues'] ?? null;
57
58 $noJsFallback = ( new Tag( 'div' ) )
59 ->addClasses( [ 'mw-widgets-tagMultiselectWidget-nojs' ] )
60 ->appendContent( $this->getNoJavaScriptFallback() );
61
62 $pending = new PendingTextInputWidget();
63
64 $this->appendContent( $noJsFallback, $pending );
65 $this->addClasses( [ 'mw-widgets-tagMultiselectWidget' ] );
66 }
67
69 public function getConfig( &$config ) {
70 if ( $this->selectedArray !== null ) {
71 $config['selected'] = $this->selectedArray;
72 }
73 if ( $this->inputName !== null ) {
74 $config['name'] = $this->inputName;
75 }
76 if ( $this->inputPlaceholder !== null ) {
77 $config['placeholder'] = $this->inputPlaceholder;
78 }
79 if ( $this->input !== null ) {
80 $config['input'] = $this->input;
81 }
82 if ( $this->tagLimit !== null ) {
83 $config['tagLimit'] = $this->tagLimit;
84 }
85 if ( $this->allowArbitrary !== null ) {
86 $config['allowArbitrary'] = $this->allowArbitrary;
87 }
88 if ( $this->allowReordering !== null ) {
89 $config['allowReordering'] = $this->allowReordering;
90 }
91 if ( $this->allowedValues !== null ) {
92 $config['allowedValues'] = $this->allowedValues;
93 }
94
95 $config['$overlay'] = true;
96 return parent::getConfig( $config );
97 }
98
106 protected function getNoJavaScriptFallback() {
107 $widget = new MultilineTextInputWidget( array_merge( [
108 'name' => $this->inputName,
109 'value' => implode( "\n", $this->selectedArray ),
110 'rows' => min( $this->tagLimit, 10 ) ?? 10,
111 ], $this->input ) );
112
113 return [ $widget ];
114 }
115
117 protected function getJavaScriptClassName() {
118 return 'mw.widgets.TagMultiselectWidget';
119 }
120}
Text input widget that displays pending animation.
Base class for widgets to select multiple users, titles, namespaces, etc.
getNoJavaScriptFallback()
Provide the implementation for clients with JavaScript disabled.