| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Widget; |
| 4 |
|
| 5 |
use OOUI\MultilineTextInputWidget; |
| 6 |
use OOUI\Widget; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class TagMultiselectWidget extends Widget { |
| 16 |
|
| 17 |
protected $selectedArray; |
| 18 |
|
| 19 |
protected $inputName; |
| 20 |
|
| 21 |
protected $inputPlaceholder; |
| 22 |
|
| 23 |
protected $input; |
| 24 |
|
| 25 |
protected $tagLimit; |
| 26 |
|
| 27 |
protected $allowArbitrary; |
| 28 |
|
| 29 |
protected $allowedValues; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public function __construct( array $config = [] ) { |
| 42 |
parent::__construct( $config ); |
| 43 |
|
| 44 |
|
| 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 |
} |