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
|
|
|
|
* text field. It creates the <textarea> tag in the
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
class TextareaField extends FormField {
|
2016-02-12 16:00:15 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Value should be XML
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $casting = array(
|
|
|
|
'Value' => 'Text',
|
2016-06-03 20:51:02 +12:00
|
|
|
'ValueEntities' => 'HTMLFragment',
|
2016-02-12 16:00:15 +13:00
|
|
|
);
|
2016-09-30 09:10:02 +13:00
|
|
|
|
|
|
|
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_TEXT;
|
|
|
|
|
|
|
|
/**
|
2015-04-27 15:15:32 +12:00
|
|
|
* Visible number of text lines.
|
|
|
|
*
|
|
|
|
* @var int
|
2012-02-10 12:15:21 +01:00
|
|
|
*/
|
|
|
|
protected $rows = 5;
|
|
|
|
|
|
|
|
/**
|
2015-04-27 15:15:32 +12:00
|
|
|
* Visible number of text columns.
|
|
|
|
*
|
|
|
|
* @var int
|
2012-02-10 12:15:21 +01:00
|
|
|
*/
|
|
|
|
protected $cols = 20;
|
2011-03-23 17:12:25 +13:00
|
|
|
|
2010-10-15 02:56:36 +00:00
|
|
|
/**
|
2016-09-30 09:10:02 +13:00
|
|
|
* Set textarea specific schema data
|
|
|
|
*/
|
|
|
|
public function getSchemaDataDefaults()
|
|
|
|
{
|
|
|
|
$data = parent::getSchemaDataDefaults();
|
|
|
|
|
|
|
|
$data['data']['rows'] = $this->getRows();
|
|
|
|
$data['data']['columns'] = $this->getColumns();
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the number of rows in the textarea
|
2010-10-15 02:56:36 +00:00
|
|
|
*
|
2015-04-27 15:15:32 +12:00
|
|
|
* @param int $rows
|
|
|
|
*
|
|
|
|
* @return $this
|
2010-10-15 02:56:36 +00:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setRows($rows) {
|
2010-10-15 02:56:36 +00:00
|
|
|
$this->rows = $rows;
|
2015-04-27 15:15:32 +12:00
|
|
|
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2010-10-15 02:56:36 +00:00
|
|
|
}
|
2015-04-27 15:15:32 +12:00
|
|
|
|
2016-02-12 16:00:15 +13:00
|
|
|
/**
|
|
|
|
* Gets number of rows
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getRows() {
|
|
|
|
return $this->rows;
|
|
|
|
}
|
|
|
|
|
2010-10-15 02:56:36 +00:00
|
|
|
/**
|
|
|
|
* Set the number of columns in the textarea
|
|
|
|
*
|
2015-04-27 15:15:32 +12:00
|
|
|
* @param int $cols
|
|
|
|
*
|
|
|
|
* @return $this
|
2010-10-15 02:56:36 +00:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setColumns($cols) {
|
2010-10-15 02:56:36 +00:00
|
|
|
$this->cols = $cols;
|
2015-04-27 15:15:32 +12:00
|
|
|
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2010-10-15 02:56:36 +00:00
|
|
|
}
|
2011-12-22 13:10:57 +01:00
|
|
|
|
2016-02-12 16:00:15 +13:00
|
|
|
/**
|
|
|
|
* Gets the number of columns in this textarea
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getColumns() {
|
|
|
|
return $this->cols;
|
|
|
|
}
|
|
|
|
|
2015-04-27 15:15:32 +12:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getAttributes() {
|
2011-12-22 13:10:57 +01:00
|
|
|
return array_merge(
|
|
|
|
parent::getAttributes(),
|
2011-03-23 17:12:25 +13:00
|
|
|
array(
|
2016-02-12 16:00:15 +13:00
|
|
|
'rows' => $this->getRows(),
|
|
|
|
'cols' => $this->getColumns(),
|
2011-12-22 13:10:57 +01:00
|
|
|
'value' => null,
|
|
|
|
'type' => null
|
2011-03-23 17:12:25 +13:00
|
|
|
)
|
|
|
|
);
|
2007-08-13 11:54:44 +00:00
|
|
|
}
|
2011-03-23 17:12:25 +13:00
|
|
|
|
2014-08-15 18:53:05 +12:00
|
|
|
|
2010-10-15 02:56:36 +00:00
|
|
|
/**
|
2015-04-27 15:15:32 +12:00
|
|
|
* {@inheritdoc}
|
2010-10-15 02:56:36 +00:00
|
|
|
*/
|
2015-04-27 15:15:32 +12:00
|
|
|
public function Type() {
|
|
|
|
$parent = parent::Type();
|
|
|
|
|
|
|
|
if($this->readonly) {
|
|
|
|
return $parent . ' readonly';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $parent;
|
2010-10-15 02:56:36 +00:00
|
|
|
}
|
2014-08-15 18:53:05 +12:00
|
|
|
|
2010-10-15 02:56:36 +00:00
|
|
|
/**
|
2016-02-12 16:00:15 +13:00
|
|
|
* Return value with all values encoded in html entities
|
|
|
|
*
|
|
|
|
* @return string Raw HTML
|
2010-10-15 02:56:36 +00:00
|
|
|
*/
|
2016-02-12 16:00:15 +13:00
|
|
|
public function ValueEntities() {
|
|
|
|
return htmlentities($this->Value(), ENT_COMPAT, 'UTF-8');
|
2011-12-22 13:10:57 +01:00
|
|
|
}
|
2012-03-24 16:04:52 +13:00
|
|
|
}
|