silverstripe-framework/Forms/DatalessField.php

85 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\Forms;
use SilverStripe\ORM\FieldType\DBHTMLText;
/**
* Abstract class for all fields without data.
* Labels, headings and the like should extend from this.
*/
class DatalessField extends FormField {
2014-08-15 08:53:05 +02:00
/**
* @var bool $allowHTML
*/
protected $allowHTML;
2014-08-15 08:53:05 +02:00
/**
* function that returns whether this field contains data.
2014-08-15 08:53:05 +02:00
* Always returns false.
*/
public function hasData() { return false; }
public function getAttributes() {
return array_merge(
parent::getAttributes(),
array(
'type' => 'hidden',
)
);
}
2014-08-15 08:53:05 +02:00
/**
* Returns the field's representation in the form.
* For dataless fields, this defaults to $Field.
2015-06-20 12:11:08 +02:00
*
* @param array $properties
* @return DBHTMLText
*/
public function FieldHolder($properties = array()) {
return $this->Field($properties);
}
/**
* Returns the field's representation in a field group.
* For dataless fields, this defaults to $Field.
*
* @param array $properties
* @return DBHTMLText
*/
public function SmallFieldHolder($properties = array()) {
return $this->Field($properties);
}
/**
* Returns a readonly version of this field
*/
public function performReadonlyTransformation() {
$clone = clone $this;
$clone->setReadonly(true);
return $clone;
}
2014-08-15 08:53:05 +02:00
/**
* @param bool $bool
* @return $this
*/
public function setAllowHTML($bool) {
$this->allowHTML = $bool;
return $this;
}
2014-08-15 08:53:05 +02:00
/**
* @return bool
*/
public function getAllowHTML() {
return $this->allowHTML;
}
public function Type() {
return 'readonly';
}
}