Clean up LiteralField

This commit is contained in:
Christopher Pitt 2015-04-27 16:00:53 +12:00
parent 72ee96cd65
commit 4c6ec7afd9

View File

@ -1,9 +1,8 @@
<?php <?php
/** /**
* This field lets you put an arbitrary piece of HTML into your forms. * This field lets you put an arbitrary piece of HTML into your forms.
* *
* <b>Usage</b>
*
* <code> * <code>
* new LiteralField ( * new LiteralField (
* $name = "literalfield", * $name = "literalfield",
@ -15,40 +14,59 @@
* @subpackage fields-dataless * @subpackage fields-dataless
*/ */
class LiteralField extends DatalessField { class LiteralField extends DatalessField {
/** /**
* @var string $content * @var string|FormField
*/ */
protected $content; protected $content;
/**
* @param string $name
* @param string|FormField $content
*/
public function __construct($name, $content) { public function __construct($name, $content) {
$this->content = $content; $this->setContent($content);
parent::__construct($name); parent::__construct($name);
} }
/**
* @param array $properties
*
* @return string
*/
public function FieldHolder($properties = array()) { public function FieldHolder($properties = array()) {
if(is_object($this->content)) { if($this->content instanceof ViewableData) {
$obj = $this->content; $context = $this->content;
if($properties)
$obj = $obj->customise($properties); if($properties) {
return $obj->forTemplate(); $context = $context->customise($properties);
} else {
return $this->content;
}
} }
return $context->forTemplate();
}
return $this->content;
}
/**
* @param array $properties
*
* @return string
*/
public function Field($properties = array()) { public function Field($properties = array()) {
return $this->FieldHolder($properties); return $this->FieldHolder($properties);
} }
/** /**
* Sets the content of this field to a new value * Sets the content of this field to a new value.
* *
* @param string $content * @param string|FormField $content
*
* @return $this
*/ */
public function setContent($content) { public function setContent($content) {
$this->content = $content; $this->content = $content;
return $this; return $this;
} }
@ -61,16 +79,25 @@ class LiteralField extends DatalessField {
/** /**
* Synonym of {@link setContent()} so that LiteralField is more compatible with other field types. * Synonym of {@link setContent()} so that LiteralField is more compatible with other field types.
*
* @param string|FormField $content
*
* @return $this
*/ */
public function setValue($value) { public function setValue($content) {
$this->setContent($value); $this->setContent($content);
return $this; return $this;
} }
/**
* @return static
*/
public function performReadonlyTransformation() { public function performReadonlyTransformation() {
$clone = clone $this; $clone = clone $this;
$clone->setReadonly(true); $clone->setReadonly(true);
return $clone; return $clone;
} }
} }