silverstripe-framework/forms/TextareaField.php

102 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2015-04-27 05:15:32 +02: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 08:53:05 +02:00
*
* <code>
* new TextareaField(
* $name = "description",
* $title = "Description",
* $value = "This is the default description"
* );
* </code>
2014-08-15 08:53:05 +02:00
*
* @package forms
* @subpackage fields-basic
*/
class TextareaField extends FormField {
private static $casting = array(
'Value' => 'HTMLText(array("shortcodes" => 0))',
);
/**
2015-04-27 05:15:32 +02:00
* Visible number of text lines.
*
* @var int
*/
protected $rows = 5;
/**
2015-04-27 05:15:32 +02:00
* Visible number of text columns.
*
* @var int
*/
protected $cols = 20;
/**
* Set the number of rows in the textarea
*
2015-04-27 05:15:32 +02:00
* @param int $rows
*
* @return $this
*/
public function setRows($rows) {
$this->rows = $rows;
2015-04-27 05:15:32 +02:00
return $this;
}
2015-04-27 05:15:32 +02:00
/**
* Set the number of columns in the textarea
*
2015-04-27 05:15:32 +02:00
* @param int $cols
*
* @return $this
*/
public function setColumns($cols) {
$this->cols = $cols;
2015-04-27 05:15:32 +02:00
return $this;
}
2015-04-27 05:15:32 +02:00
/**
* {@inheritdoc}
*/
public function getAttributes() {
return array_merge(
parent::getAttributes(),
array(
'rows' => $this->rows,
'cols' => $this->cols,
'value' => null,
'type' => null
)
);
}
2014-08-15 08:53:05 +02:00
/**
2015-04-27 05:15:32 +02:00
* {@inheritdoc}
*/
2015-04-27 05:15:32 +02:00
public function Type() {
$parent = parent::Type();
if($this->readonly) {
return $parent . ' readonly';
}
return $parent;
}
2014-08-15 08:53:05 +02:00
/**
2015-04-27 05:15:32 +02:00
* @return string
*/
public function Value() {
return htmlentities($this->value, ENT_COMPAT, 'UTF-8');
}
}