2013-11-19 12:55:50 +00:00
|
|
|
<?php
|
2013-11-19 13:08:16 +00:00
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
class HTMLTextAreaField extends HTMLFormField {
|
|
|
|
|
const DEFAULT_COLS = 80;
|
|
|
|
|
const DEFAULT_ROWS = 25;
|
|
|
|
|
|
|
|
|
|
function getCols() {
|
2013-11-19 13:08:16 +00:00
|
|
|
return isset( $this->mParams['cols'] ) ? $this->mParams['cols'] : static::DEFAULT_COLS;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getRows() {
|
2013-11-19 13:08:16 +00:00
|
|
|
return isset( $this->mParams['rows'] ) ? $this->mParams['rows'] : static::DEFAULT_ROWS;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:35:15 +00:00
|
|
|
function getSpellCheck() {
|
|
|
|
|
$val = isset( $this->mParams['spellcheck'] ) ? $this->mParams['spellcheck'] : null;
|
2015-06-26 05:32:28 +00:00
|
|
|
if ( is_bool( $val ) ) {
|
2015-05-18 22:35:15 +00:00
|
|
|
// "spellcheck" attribute literally requires "true" or "false" to work.
|
|
|
|
|
return $val === true ? 'true' : 'false';
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
function getInputHTML( $value ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$attribs = [
|
2013-11-19 12:55:50 +00:00
|
|
|
'id' => $this->mID,
|
|
|
|
|
'cols' => $this->getCols(),
|
|
|
|
|
'rows' => $this->getRows(),
|
2015-05-18 22:35:15 +00:00
|
|
|
'spellcheck' => $this->getSpellCheck(),
|
2016-02-17 09:09:32 +00:00
|
|
|
] + $this->getTooltipAndAccessKey();
|
2013-11-19 12:55:50 +00:00
|
|
|
|
|
|
|
|
if ( $this->mClass !== '' ) {
|
2013-11-19 13:08:16 +00:00
|
|
|
$attribs['class'] = $this->mClass;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$allowedParams = [
|
2013-05-02 18:27:44 +00:00
|
|
|
'placeholder',
|
|
|
|
|
'tabindex',
|
|
|
|
|
'disabled',
|
|
|
|
|
'readonly',
|
|
|
|
|
'required',
|
|
|
|
|
'autofocus'
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-05-02 18:27:44 +00:00
|
|
|
|
|
|
|
|
$attribs += $this->getAttributes( $allowedParams );
|
2014-07-30 17:56:25 +00:00
|
|
|
return Html::textarea( $this->mName, $value, $attribs );
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
2015-04-21 21:03:49 +00:00
|
|
|
|
|
|
|
|
function getInputOOUI( $value ) {
|
2015-07-08 01:27:03 +00:00
|
|
|
if ( isset( $this->mParams['cols'] ) ) {
|
|
|
|
|
throw new Exception( "OOUIHTMLForm does not support the 'cols' parameter for textareas" );
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 21:03:49 +00:00
|
|
|
$attribs = $this->getTooltipAndAccessKey();
|
|
|
|
|
|
|
|
|
|
if ( $this->mClass !== '' ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$attribs['classes'] = [ $this->mClass ];
|
2015-04-21 21:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$allowedParams = [
|
2015-04-21 21:03:49 +00:00
|
|
|
'placeholder',
|
|
|
|
|
'tabindex',
|
|
|
|
|
'disabled',
|
|
|
|
|
'readonly',
|
|
|
|
|
'required',
|
|
|
|
|
'autofocus',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2015-04-21 21:03:49 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$attribs += $this->getAttributes( $allowedParams, [
|
2015-04-21 21:03:49 +00:00
|
|
|
'tabindex' => 'tabIndex',
|
|
|
|
|
'readonly' => 'readOnly',
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2015-04-21 21:03:49 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return new OOUI\TextInputWidget( [
|
2015-04-21 21:03:49 +00:00
|
|
|
'id' => $this->mID,
|
|
|
|
|
'name' => $this->mName,
|
|
|
|
|
'multiline' => true,
|
|
|
|
|
'value' => $value,
|
2015-07-08 01:27:03 +00:00
|
|
|
'rows' => $this->getRows(),
|
2016-02-17 09:09:32 +00:00
|
|
|
] + $attribs );
|
2015-04-21 21:03:49 +00:00
|
|
|
}
|
2013-11-19 13:08:16 +00:00
|
|
|
}
|