MediaWiki master
ComplexNamespaceInputWidget.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Widget;
4
5use OOUI\CheckboxInputWidget;
6use OOUI\FieldLayout;
7use OOUI\Widget;
8
16class ComplexNamespaceInputWidget extends Widget {
17
19 protected $config;
21 protected $namespace;
23 protected $associated = null;
25 protected $associatedLabel = null;
27 protected $invert = null;
29 protected $invertLabel = null;
30
48 public function __construct( array $config = [] ) {
49 // Configuration initialization
50 $config = array_merge(
51 [
52 // Config options for nested widgets
53 'namespace' => [],
54 'invert' => [],
55 'invertLabel' => [],
56 'associated' => [],
57 'associatedLabel' => [],
58 ],
60 );
61
62 parent::__construct( $config );
63
64 // Properties
65 $this->config = $config;
66
67 $this->namespace = new NamespaceInputWidget( $config['namespace'] );
68 if ( $config['associated'] !== null ) {
69 $this->associated = new CheckboxInputWidget( array_merge(
70 [ 'value' => '1' ],
71 $config['associated']
72 ) );
73 // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
74 $this->associatedLabel = new FieldLayout(
75 $this->associated,
76 array_merge(
77 [ 'align' => 'inline' ],
78 $config['associatedLabel']
79 )
80 );
81 }
82 if ( $config['invert'] !== null ) {
83 $this->invert = new CheckboxInputWidget( array_merge(
84 [ 'value' => '1' ],
85 $config['invert']
86 ) );
87 // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
88 $this->invertLabel = new FieldLayout(
89 $this->invert,
90 array_merge(
91 [ 'align' => 'inline' ],
92 $config['invertLabel']
93 )
94 );
95 }
96
97 // Initialization
98 $this
99 ->addClasses( [ 'mw-widget-complexNamespaceInputWidget' ] )
100 ->appendContent( $this->namespace, $this->associatedLabel, $this->invertLabel );
101 }
102
104 protected function getJavaScriptClassName() {
105 return 'mw.widgets.ComplexNamespaceInputWidget';
106 }
107
109 public function getConfig( &$config ) {
110 $config = array_merge(
111 $config,
112 array_intersect_key(
113 $this->config,
114 array_fill_keys(
115 [
116 'namespace',
117 'invert',
118 'invertLabel',
119 'associated',
120 'associatedLabel'
121 ],
122 true
123 )
124 )
125 );
126 $config['namespace']['dropdown']['$overlay'] = true;
127 return parent::getConfig( $config );
128 }
129}