Treat Codex the same as OOUI, which also has separate getOOUI() and getInputOOUI() methods. With this, we can refactor the HTMLFormField subclasses that already have Codex support to override getInputCodex() instead of checking for $this->mParent instanceof CodexHTMLForm. The getCodex() method is mostly a copy of getDiv() for now. The next commit reworks this to use the correct field wrappers that correspond to Codex's Field component. Bug: T359013 Change-Id: Iccd6fec003b6ca119b13c01a43dda9e8b2aca3e2
72 lines
1.9 KiB
PHP
72 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* HTML form generation using Codex components.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* @file
|
|
*/
|
|
|
|
namespace MediaWiki\HTMLForm;
|
|
|
|
use MediaWiki\Html\Html;
|
|
|
|
/**
|
|
* Codex based HTML form
|
|
*
|
|
* @since 1.41
|
|
*/
|
|
class CodexHTMLForm extends HTMLForm {
|
|
|
|
protected $displayFormat = 'codex';
|
|
|
|
public static function loadInputFromParameters( $fieldname, $descriptor,
|
|
HTMLForm $parent = null
|
|
) {
|
|
$field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
|
|
$field->setShowEmptyLabel( false );
|
|
return $field;
|
|
}
|
|
|
|
public function getHTML( $submitResult ) {
|
|
$this->getOutput()->addModuleStyles( [
|
|
'codex-styles',
|
|
] );
|
|
|
|
return parent::getHTML( $submitResult );
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
protected function formatField( HTMLFormField $field, $value ) {
|
|
return $field->getCodex( $value );
|
|
}
|
|
|
|
protected function getFormAttributes() {
|
|
$attribs = parent::getFormAttributes();
|
|
$attribs['class'] = [ 'mw-htmlform', 'mw-htmlform-codex' ];
|
|
return $attribs;
|
|
}
|
|
|
|
public function wrapForm( $html ) {
|
|
return Html::rawElement( 'form', $this->getFormAttributes(), $html );
|
|
}
|
|
}
|
|
|
|
/** @deprecated since 1.42 */
|
|
class_alias( CodexHTMLForm::class, 'CodexHTMLForm' );
|