Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / htmlform / HTMLFormElement.php
blob66039d4c49ed33193adc003cd14f40370e2ca9a0
1 <?php
3 namespace MediaWiki\HTMLForm;
5 /**
6 * Allows custom data specific to HTMLFormField to be set for OOUI forms. A matching JS widget
7 * (defined in htmlform.Element.js) picks up the extra config when constructed using OO.ui.infuse().
9 * Currently only supports passing 'hide-if' and 'disable-if' data.
10 * @phan-file-suppress PhanUndeclaredMethod
12 * @stable to extend
14 trait HTMLFormElement {
16 /** @var array|null */
17 protected $condState = null;
18 /** @var array|null */
19 protected $modules = null;
21 public function initializeHTMLFormElement( array $config = [] ) {
22 // Properties
23 $this->condState = $config['condState'] ?? [];
24 $this->modules = $config['modules'] ?? [];
26 // Initialization
27 if ( $this->modules ) {
28 // JS code must be able to read this before infusing (before OOUI is even loaded),
29 // so we put this in a separate attribute (not with the rest of the config).
30 // And it's not needed anymore after infusing, so we don't put it in JS config at all.
31 $this->setAttributes( [ 'data-mw-modules' => implode( ',', $this->modules ) ] );
33 $this->registerConfigCallback( function ( &$config ) {
34 if ( $this->condState ) {
35 $config['condState'] = $this->condState;
37 } );
41 /** @deprecated class alias since 1.42 */
42 class_alias( HTMLFormElement::class, 'HTMLFormElement' );