wiki.techinc.nl/includes/htmlform/HTMLTextAreaField.php
Bartosz Dziewoński ee5af95167 HTMLForm: Use OOUI\Element::configFromHtmlAttributes instead of rolling our own
Depends on I0e5c956b9358b510c8473b1cfe6465ea1b5c07ef in OOjs UI.

This mostly reverts dd04b31052 and parts
of e85bd04bcd.

In addition to cleanup, it fixes bugs in HTMLFormFieldWithButton
(which did not add some attributes in OOUI mode) and HTMLMultiSelectField
(which did not do the mapping, losing some attributes in OOUI mode).

Change-Id: I0d1a5288e9edb73a0c3a8431feca9fcc67b72b6a
2016-03-09 00:08:05 +00:00

81 lines
1.8 KiB
PHP

<?php
class HTMLTextAreaField extends HTMLFormField {
const DEFAULT_COLS = 80;
const DEFAULT_ROWS = 25;
function getCols() {
return isset( $this->mParams['cols'] ) ? $this->mParams['cols'] : static::DEFAULT_COLS;
}
function getRows() {
return isset( $this->mParams['rows'] ) ? $this->mParams['rows'] : static::DEFAULT_ROWS;
}
function getSpellCheck() {
$val = isset( $this->mParams['spellcheck'] ) ? $this->mParams['spellcheck'] : null;
if ( is_bool( $val ) ) {
// "spellcheck" attribute literally requires "true" or "false" to work.
return $val === true ? 'true' : 'false';
}
return null;
}
function getInputHTML( $value ) {
$attribs = [
'id' => $this->mID,
'cols' => $this->getCols(),
'rows' => $this->getRows(),
'spellcheck' => $this->getSpellCheck(),
] + $this->getTooltipAndAccessKey();
if ( $this->mClass !== '' ) {
$attribs['class'] = $this->mClass;
}
$allowedParams = [
'placeholder',
'tabindex',
'disabled',
'readonly',
'required',
'autofocus'
];
$attribs += $this->getAttributes( $allowedParams );
return Html::textarea( $this->mName, $value, $attribs );
}
function getInputOOUI( $value ) {
if ( isset( $this->mParams['cols'] ) ) {
throw new Exception( "OOUIHTMLForm does not support the 'cols' parameter for textareas" );
}
$attribs = $this->getTooltipAndAccessKey();
if ( $this->mClass !== '' ) {
$attribs['classes'] = [ $this->mClass ];
}
$allowedParams = [
'placeholder',
'tabindex',
'disabled',
'readonly',
'required',
'autofocus',
];
$attribs += OOUI\Element::configFromHtmlAttributes(
$this->getAttributes( $allowedParams )
);
return new OOUI\TextInputWidget( [
'id' => $this->mID,
'name' => $this->mName,
'multiline' => true,
'value' => $value,
'rows' => $this->getRows(),
] + $attribs );
}
}