diff --git a/includes/htmlform/CodexHTMLForm.php b/includes/htmlform/CodexHTMLForm.php index 84bf4a7c202..0964e60c63c 100644 --- a/includes/htmlform/CodexHTMLForm.php +++ b/includes/htmlform/CodexHTMLForm.php @@ -29,15 +29,8 @@ use MediaWiki\Html\Html; * @since 1.41 */ class CodexHTMLForm extends HTMLForm { - /** - * Symbolic display format name. - * Note this is `vform` rather than `div` - * to avoid the div.mw-label wrapper - * on labels. - * - * @var string - */ - protected $displayFormat = 'vform'; + + protected $displayFormat = 'codex'; public static function loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent = null @@ -55,6 +48,14 @@ class CodexHTMLForm extends HTMLForm { return parent::getHTML( $submitResult ); } + /** + * @inheritDoc + */ + protected function formatField( HTMLFormField $field, $value ) { + // The "cdx-..." classes are added magically in the Html class. :( + return $field->getVForm( $value ); + } + protected function getFormAttributes() { $attribs = parent::getFormAttributes(); $attribs['class'] = [ 'mw-htmlform', 'mw-htmlform-codex' ]; diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index d167d667c6a..538d6d75b92 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -2013,12 +2013,18 @@ class HTMLForm extends ContextSource { */ protected function formatField( HTMLFormField $field, $value ) { $displayFormat = $this->getDisplayFormat(); - - // Conveniently, PHP method names are case-insensitive. - // For grep: this can call getDiv, getRaw, getInline, getVForm, getOOUI - $getFieldHtmlMethod = $displayFormat === 'table' ? 'getTableRow' : ( 'get' . $displayFormat ); - - return $field->$getFieldHtmlMethod( $value ); + switch ( $displayFormat ) { + case 'table': + return $field->getTableRow( $value ); + case 'div': + return $field->getDiv( $value ); + case 'raw': + return $field->getRaw( $value ); + case 'inline': + return $field->getInline( $value ); + default: + throw new LogicException( 'Not implemented' ); + } } /** diff --git a/includes/htmlform/OOUIHTMLForm.php b/includes/htmlform/OOUIHTMLForm.php index bcd532df7ff..1a978486b08 100644 --- a/includes/htmlform/OOUIHTMLForm.php +++ b/includes/htmlform/OOUIHTMLForm.php @@ -43,10 +43,6 @@ class OOUIHTMLForm extends HTMLForm { $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.ooui.styles' ); } - /** - * Symbolic display format name. - * @var string - */ protected $displayFormat = 'ooui'; public static function loadInputFromParameters( $fieldname, $descriptor, @@ -172,6 +168,14 @@ class OOUIHTMLForm extends HTMLForm { return $layout; } + /** + * @inheritDoc + * @return OOUI\FieldLayout HTML + */ + protected function formatField( HTMLFormField $field, $value ) { + return $field->getOOUI( $value ); + } + /** * Put a form section together from the individual fields' HTML, merging it and wrapping. * @param OOUI\FieldLayout[] $fieldsHtml Array of outputs from formatField() diff --git a/includes/htmlform/VFormHTMLForm.php b/includes/htmlform/VFormHTMLForm.php index 0bf117de747..7597725653b 100644 --- a/includes/htmlform/VFormHTMLForm.php +++ b/includes/htmlform/VFormHTMLForm.php @@ -35,10 +35,6 @@ class VFormHTMLForm extends HTMLForm { */ protected $mWrapperLegend = false; - /** - * Symbolic display format name. - * @var string - */ protected $displayFormat = 'vform'; public static function loadInputFromParameters( $fieldname, $descriptor, @@ -64,6 +60,13 @@ class VFormHTMLForm extends HTMLForm { return parent::getHTML( $submitResult ); } + /** + * @inheritDoc + */ + protected function formatField( HTMLFormField $field, $value ) { + return $field->getVForm( $value ); + } + protected function getFormAttributes() { return [ 'class' => [ 'mw-htmlform', 'mw-ui-vform', 'mw-ui-container' ] ] + parent::getFormAttributes();