silverstripe-framework/src/Forms/DatalessField.php

95 lines
1.8 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.
*/
2016-11-29 00:31:16 +01:00
class DatalessField extends FormField
{
2014-08-15 08:53:05 +02:00
2016-11-29 00:31:16 +01:00
/**
* @var bool $allowHTML
*/
protected $allowHTML;
2014-08-15 08:53:05 +02:00
2016-11-29 00:31:16 +01:00
/**
* function that returns whether this field contains data.
* Always returns false.
*/
public function hasData()
{
return false;
}
2016-11-29 00:31:16 +01:00
public function getAttributes()
{
return array_merge(
parent::getAttributes(),
array(
'type' => 'hidden',
)
);
}
2014-08-15 08:53:05 +02:00
2016-11-29 00:31:16 +01:00
/**
* Returns the field's representation in the form.
* For dataless fields, this defaults to $Field.
*
* @param array $properties
* @return DBHTMLText
*/
public function FieldHolder($properties = array())
{
return $this->Field($properties);
}
2016-11-29 00:31:16 +01:00
/**
* 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);
}
2016-11-29 00:31:16 +01:00
/**
* 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
2016-11-29 00:31:16 +01:00
/**
* @param bool $bool
* @return $this
*/
public function setAllowHTML($bool)
{
$this->allowHTML = $bool;
return $this;
}
2014-08-15 08:53:05 +02:00
2016-11-29 00:31:16 +01:00
/**
* @return bool
*/
public function getAllowHTML()
{
return $this->allowHTML;
}
2016-11-29 00:31:16 +01:00
public function Type()
{
return 'readonly';
}
}