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;
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __construct($name, $content) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$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
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function FieldHolder($properties = array()) {
|
2012-04-11 08:07:55 +02:00
|
|
|
if(is_object($this->content)) {
|
|
|
|
$obj = $this->content;
|
|
|
|
if($properties)
|
|
|
|
$obj = $obj->customise($properties);
|
|
|
|
return $obj->forTemplate();
|
|
|
|
} else {
|
|
|
|
return $this->content;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Field($properties = array()) {
|
2012-04-11 08:07:55 +02:00
|
|
|
return $this->FieldHolder($properties);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
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
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setContent($content) {
|
2008-10-16 15:26:25 +02:00
|
|
|
$this->content = $content;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2008-10-16 15:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getContent() {
|
2008-10-16 15:26:25 +02:00
|
|
|
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.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setValue($value) {
|
2012-02-17 13:35:26 +01:00
|
|
|
$this->setContent($value);
|
|
|
|
return $this;
|
2009-05-31 13:01:30 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public 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-03-23 05:12:25 +01:00
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|