Blame view

framework/forms/LiteralField.php 1.45 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  <?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
  	 */
  	protected $content;
  	
  	public function __construct($name, $content) {
  		$this->content = $content;
  		
  		parent::__construct($name);
  	}
  	
  	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;
  		}
  	}
  
  	public function Field($properties = array()) {
  		return $this->FieldHolder($properties);
  	}
  
  	/**
  	 * Sets the content of this field to a new value
  	 *
  	 * @param string $content
  	 */
  	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.
  	 */
  	public function setValue($value) {
  		$this->setContent($value);
  		return $this;
  	}
  
  	public function performReadonlyTransformation() {
  		$clone = clone $this;
  		$clone->setReadonly(true);
  		return $clone;
  	}
  
  }