2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This field lets you put an arbitrary piece of HTML into your forms.
|
2008-10-16 15:26:25 +02:00
|
|
|
*
|
2010-10-15 05:55:22 +02:00
|
|
|
* <b>Usage</b>
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* new LiteralField (
|
|
|
|
* $name = "literalfield",
|
|
|
|
* $content = '<b>some bold text</b> and <a href="http://silverstripe.com">a link</a>'
|
|
|
|
* )
|
|
|
|
* </code>
|
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-dataless
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class LiteralField extends DatalessField {
|
2008-10-16 15:26:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string $content
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
protected $content;
|
|
|
|
|
|
|
|
function __construct($name, $content) {
|
|
|
|
$this->content = $content;
|
2008-10-16 15:26:25 +02:00
|
|
|
|
|
|
|
parent::__construct($name);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-10-16 15:26:25 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function FieldHolder() {
|
|
|
|
return is_object($this->content) ? $this->content->forTemplate() : $this->content;
|
|
|
|
}
|
2008-10-16 15:26:25 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function Field() {
|
|
|
|
return $this->FieldHolder();
|
|
|
|
}
|
|
|
|
|
2008-10-16 15:26:25 +02:00
|
|
|
/**
|
|
|
|
* Sets the content of this field to a new value
|
2011-08-30 02:41:50 +02:00
|
|
|
*
|
2008-10-16 15:26:25 +02:00
|
|
|
* @param string $content
|
|
|
|
*/
|
|
|
|
function setContent($content) {
|
|
|
|
$this->content = $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function getContent() {
|
|
|
|
return $this->content;
|
|
|
|
}
|
2009-05-31 13:01:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Synonym of {@link setContent()} so that LiteralField is more compatible with other field types.
|
|
|
|
*/
|
|
|
|
function setValue($value) {
|
|
|
|
return $this->setContent($value);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
function performReadonlyTransformation() {
|
2008-12-04 23:38:32 +01:00
|
|
|
$clone = clone $this;
|
|
|
|
$clone->setReadonly(true);
|
|
|
|
return $clone;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-08-30 02:41:50 +02:00
|
|
|
}
|