MediaWiki master
SelectWithInputWidget.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Widget;
4
5use OOUI\DropdownInputWidget;
6use OOUI\TextInputWidget;
7use OOUI\Widget;
8
15class SelectWithInputWidget extends Widget {
17 protected $config;
19 protected $textinput;
21 protected $dropdowninput;
22
33 public function __construct( array $config = [] ) {
34 // Configuration initialization
35 $config = array_merge(
36 [
37 'textinput' => [],
38 'dropdowninput' => [],
39 'or' => false,
40 'required' => false,
41 ],
43 );
44
45 if ( isset( $config['disabled'] ) && $config['disabled'] ) {
46 $config['textinput']['disabled'] = true;
47 $config['dropdowninput']['disabled'] = true;
48 }
49
50 $config['textinput']['required'] = $config['or'] ? false : $config['required'];
51 $config['dropdowninput']['required'] = $config['required'];
52
53 parent::__construct( $config );
54
55 // Properties
56 $this->config = $config;
57 $this->textinput = new TextInputWidget( $config['textinput'] );
58 $this->dropdowninput = new DropdownInputWidget( $config['dropdowninput'] );
59
60 // Initialization
61 $this
62 ->addClasses( [ 'mw-widget-selectWithInputWidget' ] )
63 ->appendContent( $this->dropdowninput, $this->textinput );
64
65 if ( $config['or'] && $this->dropdowninput->getValue() !== 'other' ) {
66 $this->addClasses( [ 'mw-widget-selectWithInputWidget-hideTextInput' ] );
67 }
68 }
69
71 public function setLabelledBy( $id ) {
72 if ( $id ) {
73 $this->dropdowninput->setLabelledBy( $id );
74 $this->textinput->setLabelledBy( $id );
75 } else {
76 $this->dropdowninput->removeAttributes( [ 'aria-labelledby' ] );
77 $this->textinput->removeAttributes( [ 'aria-labelledby' ] );
78 }
79 }
80
82 protected function getJavaScriptClassName() {
83 return 'mw.widgets.SelectWithInputWidget';
84 }
85
87 public function getConfig( &$config ) {
88 $config['textinput'] = $this->config['textinput'];
89 $config['dropdowninput'] = $this->config['dropdowninput'];
90 $config['dropdowninput']['dropdown']['$overlay'] = true;
91 $config['or'] = $this->config['or'];
92 $config['required'] = $this->config['required'];
93 return parent::getConfig( $config );
94 }
95}
__construct(array $config=[])
A version of the SelectWithInputWidget, with or set to true.