mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Clean up LiteralField
This commit is contained in:
parent
72ee96cd65
commit
4c6ec7afd9
@ -1,76 +1,103 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This field lets you put an arbitrary piece of HTML into your forms.
|
||||
*
|
||||
* <b>Usage</b>
|
||||
*
|
||||
*
|
||||
* <code>
|
||||
* new LiteralField (
|
||||
* $name = "literalfield",
|
||||
* $content = '<b>some bold text</b> and <a href="http://silverstripe.com">a link</a>'
|
||||
* )
|
||||
* </code>
|
||||
*
|
||||
*
|
||||
* @package forms
|
||||
* @subpackage fields-dataless
|
||||
*/
|
||||
class LiteralField extends DatalessField {
|
||||
|
||||
/**
|
||||
* @var string $content
|
||||
* @var string|FormField
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string|FormField $content
|
||||
*/
|
||||
public function __construct($name, $content) {
|
||||
$this->content = $content;
|
||||
|
||||
$this->setContent($content);
|
||||
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $properties
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function FieldHolder($properties = array()) {
|
||||
if(is_object($this->content)) {
|
||||
$obj = $this->content;
|
||||
if($properties)
|
||||
$obj = $obj->customise($properties);
|
||||
return $obj->forTemplate();
|
||||
} else {
|
||||
return $this->content;
|
||||
if($this->content instanceof ViewableData) {
|
||||
$context = $this->content;
|
||||
|
||||
if($properties) {
|
||||
$context = $context->customise($properties);
|
||||
}
|
||||
|
||||
return $context->forTemplate();
|
||||
}
|
||||
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $properties
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function Field($properties = array()) {
|
||||
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) {
|
||||
$this->content = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContent() {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Synonym of {@link setContent()} so that LiteralField is more compatible with other field types.
|
||||
*
|
||||
* @param string|FormField $content
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value) {
|
||||
$this->setContent($value);
|
||||
public function setValue($content) {
|
||||
$this->setContent($content);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public function performReadonlyTransformation() {
|
||||
$clone = clone $this;
|
||||
|
||||
$clone->setReadonly(true);
|
||||
|
||||
return $clone;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user