2016-07-30 23:19:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
2024-02-08 15:30:18 +00:00
|
|
|
namespace MediaWiki\HTMLForm;
|
|
|
|
|
|
2016-07-30 23:19:26 +00:00
|
|
|
/**
|
2018-01-17 07:04:01 +00:00
|
|
|
* Allows custom data specific to HTMLFormField to be set for OOUI forms. A matching JS widget
|
2016-07-30 23:19:26 +00:00
|
|
|
* (defined in htmlform.Element.js) picks up the extra config when constructed using OO.ui.infuse().
|
|
|
|
|
*
|
2021-04-25 15:25:19 +00:00
|
|
|
* Currently only supports passing 'hide-if' and 'disable-if' data.
|
2019-08-31 16:14:38 +00:00
|
|
|
* @phan-file-suppress PhanUndeclaredMethod
|
2020-07-10 19:23:59 +00:00
|
|
|
*
|
|
|
|
|
* @stable to extend
|
2016-07-30 23:19:26 +00:00
|
|
|
*/
|
|
|
|
|
trait HTMLFormElement {
|
|
|
|
|
|
2024-09-13 20:19:49 +00:00
|
|
|
/** @var array|null */
|
2021-04-25 15:25:19 +00:00
|
|
|
protected $condState = null;
|
2024-09-13 20:19:49 +00:00
|
|
|
/** @var array|null */
|
2016-07-31 14:56:23 +00:00
|
|
|
protected $modules = null;
|
2016-07-30 23:19:26 +00:00
|
|
|
|
|
|
|
|
public function initializeHTMLFormElement( array $config = [] ) {
|
|
|
|
|
// Properties
|
2021-12-18 03:47:45 +00:00
|
|
|
$this->condState = $config['condState'] ?? [];
|
2017-10-06 22:17:58 +00:00
|
|
|
$this->modules = $config['modules'] ?? [];
|
2016-07-30 23:19:26 +00:00
|
|
|
|
|
|
|
|
// Initialization
|
2016-07-31 14:56:23 +00:00
|
|
|
if ( $this->modules ) {
|
2018-01-17 07:04:01 +00:00
|
|
|
// JS code must be able to read this before infusing (before OOUI is even loaded),
|
2016-07-31 14:56:23 +00:00
|
|
|
// so we put this in a separate attribute (not with the rest of the config).
|
|
|
|
|
// And it's not needed anymore after infusing, so we don't put it in JS config at all.
|
|
|
|
|
$this->setAttributes( [ 'data-mw-modules' => implode( ',', $this->modules ) ] );
|
|
|
|
|
}
|
2017-06-26 16:35:31 +00:00
|
|
|
$this->registerConfigCallback( function ( &$config ) {
|
2021-12-18 03:47:45 +00:00
|
|
|
if ( $this->condState ) {
|
2021-04-25 15:25:19 +00:00
|
|
|
$config['condState'] = $this->condState;
|
2016-07-30 23:19:26 +00:00
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-08 15:30:18 +00:00
|
|
|
|
2024-03-07 21:56:58 +00:00
|
|
|
/** @deprecated class alias since 1.42 */
|
2024-02-08 15:30:18 +00:00
|
|
|
class_alias( HTMLFormElement::class, 'HTMLFormElement' );
|