2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-10 16:03:34 +01:00
|
|
|
* 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.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-basic
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class ReadonlyField extends FormField {
|
|
|
|
|
2008-08-12 04:58:48 +02:00
|
|
|
protected $readonly = true;
|
|
|
|
|
2013-01-07 06:44:01 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2013-01-07 06:44:01 +01:00
|
|
|
* 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.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2013-01-07 06:44:01 +01:00
|
|
|
* @param boolean $includeHiddenField
|
|
|
|
*/
|
|
|
|
public function setIncludeHiddenField($includeHiddenField) {
|
|
|
|
$this->includeHiddenField = $includeHiddenField;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function performReadonlyTransformation() {
|
2008-12-04 23:38:32 +01:00
|
|
|
return clone $this;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-12-22 13:10:57 +01:00
|
|
|
|
2015-06-20 12:11:08 +02:00
|
|
|
/**
|
|
|
|
* @param array $properties
|
|
|
|
* @return HTMLText
|
|
|
|
*/
|
2013-01-07 06:44:01 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Value() {
|
2011-12-22 13:10:57 +01:00
|
|
|
if($this->value) return $this->dontEscape ? $this->value : Convert::raw2xml($this->value);
|
|
|
|
else return '<i>(' . _t('FormField.NONE', 'none') . ')</i>';
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getAttributes() {
|
2011-12-22 13:10:57 +01:00
|
|
|
return array_merge(
|
|
|
|
parent::getAttributes(),
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
2013-01-07 06:44:01 +01:00
|
|
|
'value' => $this->readonly ? null : $this->value,
|
2011-12-22 13:10:57 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Type() {
|
2011-12-22 13:10:57 +01:00
|
|
|
return 'readonly';
|
|
|
|
}
|
2014-11-12 03:19:12 +01:00
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|