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