Version: current

     1 <?php
     2 /**
     3  * This field lets you put an arbitrary piece of HTML into your forms.
     4  *
     5  * @package forms
     6  * @subpackage fields-dataless
     7  */
     8 class LiteralField extends DatalessField {
     9
    10     /**
    11      * @var string $content
    12      */
    13     protected $content;
    14
    15     function __construct($name, $content) {
    16         $this->content = $content;
    17
    18         parent::__construct($name);
    19     }
    20
    21     function Field() {
    22         $attributes = array(
    23             'type' => 'literal',
    24         );
    25         return $this->createTag('span', $attributes, is_object($this->content) ? $this->content->forTemplate() : $this->content);
    26     }
    27
    28     /**
    29      * Sets the content of this field to a new value
    30      * @param string $content
    31      */
    32     function setContent($content) {
    33         $this->content = $content;
    34     }
    35
    36     /**
    37      * @return string
    38      */
    39     function getContent() {
    40         return $this->content;
    41     }
    42
    43     /**
    44      * Synonym of {@link setContent()} so that LiteralField is more compatible with other field types.
    45      */
    46     function setValue($value) {
    47         return $this->setContent($value);
    48     }
    49
    50     function performReadonlyTransformation() {
    51         $clone = clone $this;
    52         $clone->setReadonly(true);
    53         return $clone;
    54     }
    55 }
    56
    57 ?>

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -