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
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->allowReordering !== null ) {
88 $config['allowReordering'] = $this->allowReordering;
89 }
90 if ( $this->allowedValues !== null ) {
91 $config['allowedValues'] = $this->allowedValues;
92 }
93
94 $config['$overlay'] = true;
95 return parent::getConfig( $config );
96 }
97
105 protected function getNoJavaScriptFallback() {
106 $widget = new MultilineTextInputWidget( array_merge( [
107 'name' => $this->inputName,
108 'value' => implode( "\n", $this->selectedArray ),
109 'rows' => min( $this->tagLimit, 10 ) ?? 10,
110 ], $this->input ) );
111
112 return [ $widget ];
113 }
114
115 protected function getJavaScriptClassName() {
116 return 'mw.widgets.TagMultiselectWidget';
117 }
118}
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.