Blame view

framework/forms/ReadonlyField.php 1.76 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
  <?php
  /**
   * Read-only field to display a non-editable value with a label.
   * Consider using an {@link LabelField} if you just need a label-less
   * value display.
   * 
   * @package forms
   * @subpackage fields-basic
   */
  class ReadonlyField extends FormField {
  
  	protected $readonly = true;
  
  	/**
  	 * Include a hidden field in the HTML for the readonly field
  	 * @var boolean
  	 */
  	protected $includeHiddenField = false;
  
  	/**
  	 * If true, a hidden field will be included in the HTML for the readonly field.
  	 * 
  	 * This can be useful if you need to pass the data through on the form submission, as
  	 * long as it's okay than an attacker could change the data before it's submitted.
  	 *
  	 * This is disabled by default as it can introduce security holes if the data is not
  	 * allowed to be modified by the user.
  	 * 
  	 * @param boolean $includeHiddenField
  	 */
  	public function setIncludeHiddenField($includeHiddenField) {
  		$this->includeHiddenField = $includeHiddenField;
  	}
  
  	public function performReadonlyTransformation() {
  		return clone $this;
  	}
  
  	public function Field($properties = array()) {
  		// Include a hidden field in the HTML
  		if($this->includeHiddenField && $this->readonly) {
  			$hidden = clone $this;
  			$hidden->setReadonly(false);
  			return parent::Field($properties) . $hidden->Field($properties);
  
  		} else {
  			return parent::Field($properties);
  		}
  	}
  
  	public function Value() {
  		if($this->value) return $this->dontEscape ? $this->value : Convert::raw2xml($this->value);
  		else return '<i>(' . _t('FormField.NONE', 'none') . ')</i>';
  	}
  
  	public function getAttributes() {
  		return array_merge(
  			parent::getAttributes(),
  			array(
  				'type' => 'hidden',
  				'value' => $this->readonly ? null : $this->value,
  			)
  		);
  	}
  
  	public function Type() {
  		return 'readonly';
  	}
  }