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