20 $value = $request->getText( $this->mName, $this->
getDefault() ??
'' );
22 $tagsArray = explode(
"\n", $value );
24 $tagsArray = array_values( array_filter( $tagsArray,
static function ( $tag ) {
25 return trim( $tag ) !==
'';
28 $uniqueTags = array_unique( $tagsArray );
31 return implode(
"\n", $uniqueTags );
35 if ( $value ===
null ) {
40 $tagsArray = explode(
"\n", $value );
42 if ( isset( $this->mParams[
'max'] ) && ( count( $tagsArray ) > $this->mParams[
'max'] ) ) {
43 return $this->
msg(
'htmlform-multiselect-toomany', $this->mParams[
'max'] );
46 foreach ( $tagsArray as $tag ) {
47 $result = parent::validate( $tag, $alldata );
48 if ( $result !==
true ) {
52 if ( empty( $this->mParams[
'allowArbitrary'] ) && $tag ) {
53 $allowedValues = $this->mParams[
'allowedValues'] ?? [];
54 if ( !in_array( $tag, $allowedValues ) ) {
55 return $this->
msg(
'htmlform-tag-not-allowed', $tag )->escaped();
64 $this->mParent->getOutput()->enableOOUI();
69 $this->mParent->getOutput()->addModuleStyles(
'mediawiki.widgets.TagMultiselectWidget.styles' );
73 if ( isset( $this->mParams[
'id'] ) ) {
74 $params[
'id'] = $this->mParams[
'id'];
77 if ( isset( $this->mParams[
'disabled'] ) ) {
78 $params[
'disabled'] = $this->mParams[
'disabled'];
81 if ( isset( $this->mParams[
'default'] ) ) {
82 $params[
'default'] = $this->mParams[
'default'];
85 $params[
'placeholder'] = $this->mParams[
'placeholder'] ??
86 $this->
msg(
'mw-widgets-tagmultiselect-placeholder' )->plain();
88 if ( isset( $this->mParams[
'max'] ) ) {
89 $params[
'tagLimit'] = $this->mParams[
'max'];
92 if ( isset( $this->mParams[
'allowArbitrary'] ) ) {
93 $params[
'allowArbitrary'] = $this->mParams[
'allowArbitrary'];
96 if ( isset( $this->mParams[
'allowedValues'] ) ) {
97 $params[
'allowedValues'] = $this->mParams[
'allowedValues'];
100 if ( isset( $this->mParams[
'input'] ) ) {
101 $params[
'input'] = $this->mParams[
'input'];
104 if ( $value !==
null ) {
106 $params[
'default'] = $value ===
'' ? [] : explode(
"\n", $value );
110 $params[
'infusable'] =
true;
111 $params[
'classes'] = [
'mw-htmlform-autoinfuse' ];
121 $widget->setAttributes( [
'data-mw-modules' => implode(
',', $this->
getOOUIModules() ) ] );
130 return [
'mediawiki.widgets.TagMultiselectWidget' ];
Implements a tag multiselect input field for arbitrary values.
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
loadDataFromRequest( $request)
Get the value that this input has been set to from a posted form, or the input's default value if it ...
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
getInputWidget( $params)
Stability: stableto overrideWidget
shouldInfuseOOUI()
Whether the field should be automatically infused.