e553218fa559abb2045eaeb5c80c9197a3280900
[lhc/web/wiklou.git] / includes / htmlform / HTMLFormElement.php
1 <?php
2
3 /**
4 * Allows custom data specific to HTMLFormField to be set for OOjs UI forms. A matching JS widget
5 * (defined in htmlform.Element.js) picks up the extra config when constructed using OO.ui.infuse().
6 *
7 * Currently only supports passing 'hide-if' data.
8 */
9 trait HTMLFormElement {
10
11 protected $hideIf = null;
12
13 public function initializeHTMLFormElement( array $config = [] ) {
14 // Properties
15 $this->hideIf = isset( $config['hideIf'] ) ? $config['hideIf'] : null;
16
17 // Initialization
18 if ( $this->hideIf ) {
19 $this->addClasses( [ 'mw-htmlform-hide-if' ] );
20 }
21 $this->registerConfigCallback( function( &$config ) {
22 if ( $this->hideIf !== null ) {
23 $config['hideIf'] = $this->hideIf;
24 }
25 } );
26 }
27 }
28
29 class HTMLFormFieldLayout extends OOUI\FieldLayout {
30 use HTMLFormElement;
31
32 public function __construct( $fieldWidget, array $config = [] ) {
33 // Parent constructor
34 parent::__construct( $fieldWidget, $config );
35 // Traits
36 $this->initializeHTMLFormElement( $config );
37 }
38
39 protected function getJavaScriptClassName() {
40 return 'mw.htmlform.FieldLayout';
41 }
42 }
43
44 class HTMLFormActionFieldLayout extends OOUI\ActionFieldLayout {
45 use HTMLFormElement;
46
47 public function __construct( $fieldWidget, $buttonWidget = false, array $config = [] ) {
48 // Parent constructor
49 parent::__construct( $fieldWidget, $buttonWidget, $config );
50 // Traits
51 $this->initializeHTMLFormElement( $config );
52 }
53
54 protected function getJavaScriptClassName() {
55 return 'mw.htmlform.ActionFieldLayout';
56 }
57 }