2007-07-19 10:40:28 +00:00
|
|
|
<?php
|
2015-04-27 15:15:32 +12:00
|
|
|
|
2016-08-19 10:51:35 +12:00
|
|
|
namespace SilverStripe\Forms;
|
|
|
|
|
2007-07-19 10:40:28 +00:00
|
|
|
/**
|
2008-10-20 10:05:05 +00:00
|
|
|
* TextareaField creates a multi-line text field,
|
|
|
|
* allowing more data to be entered than a standard
|
2018-10-09 10:46:45 +02:00
|
|
|
* text field. It creates the `<textarea>` tag in the
|
2008-10-20 10:05:05 +00:00
|
|
|
* form HTML.
|
2014-08-15 18:53:05 +12:00
|
|
|
*
|
2010-10-15 03:55:22 +00:00
|
|
|
* <code>
|
|
|
|
* new TextareaField(
|
|
|
|
* $name = "description",
|
|
|
|
* $title = "Description",
|
|
|
|
* $value = "This is the default description"
|
|
|
|
* );
|
|
|
|
* </code>
|
2007-07-19 10:40:28 +00:00
|
|
|
*/
|
2016-11-29 12:31:16 +13:00
|
|
|
class TextareaField extends FormField
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Value should be XML
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2020-04-20 18:58:09 +01:00
|
|
|
private static $casting = [
|
2016-11-29 12:31:16 +13:00
|
|
|
'Value' => 'Text',
|
2020-04-20 19:07:53 +12:00
|
|
|
'ValueEntities' => 'HTMLFragment([\'shortcodes\' => false])',
|
2020-04-20 18:58:09 +01:00
|
|
|
];
|
2017-12-04 16:40:40 +13:00
|
|
|
|
2016-09-30 09:10:02 +13:00
|
|
|
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_TEXT;
|
2017-12-04 16:40:40 +13:00
|
|
|
|
2016-09-30 09:10:02 +13:00
|
|
|
/**
|
2016-11-29 12:31:16 +13:00
|
|
|
* Visible number of text lines.
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $rows = 5;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Visible number of text columns.
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $cols = 20;
|
|
|
|
|
2017-12-04 16:40:40 +13:00
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $maxLength;
|
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
/**
|
|
|
|
* Set textarea specific schema data
|
2016-09-30 09:10:02 +13:00
|
|
|
*/
|
|
|
|
public function getSchemaDataDefaults()
|
|
|
|
{
|
|
|
|
$data = parent::getSchemaDataDefaults();
|
|
|
|
$data['data']['rows'] = $this->getRows();
|
|
|
|
$data['data']['columns'] = $this->getColumns();
|
2017-12-04 16:40:40 +13:00
|
|
|
$data['data']['maxlength'] = $this->getMaxLength();
|
2016-09-30 09:10:02 +13:00
|
|
|
return $data;
|
|
|
|
}
|
2017-12-04 16:40:40 +13:00
|
|
|
|
2016-09-30 09:10:02 +13:00
|
|
|
/**
|
|
|
|
* Set the number of rows in the textarea
|
2016-11-29 12:31:16 +13:00
|
|
|
*
|
|
|
|
* @param int $rows
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setRows($rows)
|
|
|
|
{
|
|
|
|
$this->rows = $rows;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets number of rows
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getRows()
|
|
|
|
{
|
|
|
|
return $this->rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the number of columns in the textarea
|
|
|
|
*
|
|
|
|
* @param int $cols
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setColumns($cols)
|
|
|
|
{
|
|
|
|
$this->cols = $cols;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the number of columns in this textarea
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getColumns()
|
|
|
|
{
|
|
|
|
return $this->cols;
|
|
|
|
}
|
|
|
|
|
2017-12-04 16:40:40 +13:00
|
|
|
/**
|
|
|
|
* @param int $maxLength
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setMaxLength($maxLength)
|
|
|
|
{
|
|
|
|
$this->maxLength = $maxLength;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return null|int
|
|
|
|
*/
|
|
|
|
public function getMaxLength()
|
|
|
|
{
|
|
|
|
return $this->maxLength;
|
|
|
|
}
|
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getAttributes()
|
|
|
|
{
|
2017-12-08 09:58:52 +13:00
|
|
|
$attributes = array_merge(
|
2016-11-29 12:31:16 +13:00
|
|
|
parent::getAttributes(),
|
2020-04-20 18:58:09 +01:00
|
|
|
[
|
2016-11-29 12:31:16 +13:00
|
|
|
'rows' => $this->getRows(),
|
|
|
|
'cols' => $this->getColumns(),
|
|
|
|
'value' => null,
|
2017-12-04 16:40:40 +13:00
|
|
|
'type' => null,
|
2020-04-20 18:58:09 +01:00
|
|
|
]
|
2016-11-29 12:31:16 +13:00
|
|
|
);
|
2017-12-08 09:58:52 +13:00
|
|
|
|
|
|
|
$maxLength = $this->getMaxLength();
|
2017-12-11 09:00:04 +13:00
|
|
|
if ($maxLength) {
|
2017-12-08 09:58:52 +13:00
|
|
|
$attributes['maxlength'] = $maxLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $attributes;
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function Type()
|
|
|
|
{
|
|
|
|
$parent = parent::Type();
|
|
|
|
|
|
|
|
if ($this->readonly) {
|
|
|
|
return $parent . ' readonly';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return value with all values encoded in html entities
|
|
|
|
*
|
|
|
|
* @return string Raw HTML
|
|
|
|
*/
|
|
|
|
public function ValueEntities()
|
|
|
|
{
|
|
|
|
return htmlentities($this->Value(), ENT_COMPAT, 'UTF-8');
|
|
|
|
}
|
2012-03-24 16:04:52 +13:00
|
|
|
}
|