4 * Allows custom data specific to HTMLFormField to be set for OOUI forms. A matching JS widget
5 * (defined in htmlform.Element.js) picks up the extra config when constructed using OO.ui.infuse().
7 * Currently only supports passing 'hide-if' data.
8 * @phan-file-suppress PhanUndeclaredMethod
10 trait HTMLFormElement
{
12 protected $hideIf = null;
13 protected $modules = null;
15 public function initializeHTMLFormElement( array $config = [] ) {
17 $this->hideIf
= $config['hideIf'] ??
null;
18 $this->modules
= $config['modules'] ??
[];
21 if ( $this->hideIf
) {
22 $this->addClasses( [ 'mw-htmlform-hide-if' ] );
24 if ( $this->modules
) {
25 // JS code must be able to read this before infusing (before OOUI is even loaded),
26 // so we put this in a separate attribute (not with the rest of the config).
27 // And it's not needed anymore after infusing, so we don't put it in JS config at all.
28 $this->setAttributes( [ 'data-mw-modules' => implode( ',', $this->modules
) ] );
30 $this->registerConfigCallback( function ( &$config ) {
31 if ( $this->hideIf
!== null ) {
32 $config['hideIf'] = $this->hideIf
;