diff --git a/forms/DatalessField.php b/forms/DatalessField.php
index 80afa5cb6..1c24beaf1 100755
--- a/forms/DatalessField.php
+++ b/forms/DatalessField.php
@@ -2,10 +2,31 @@
/**
* Abstract class for all fields without data.
* Labels, headings and the like should extend from this.
+ *
* @package forms
* @subpackage fields-dataless
*/
class DatalessField extends FormField {
+
+ /**
+ * @var bool $allowHTML
+ */
+ protected $allowHTML;
+
+ /**
+ * @param string $name
+ * @param string $title The label itslef
+ * @param string $class An HTML class to apply to the label (Deprecated: use addExtraClass())
+ * @param boolean $allowHTML Determine if the tag content needs to be escaped (Deprecated: use setAllowHTML())
+ * @param Form $form
+ */
+ function __construct($name, $title = null, $className = "", $allowHTML = false, $form = null) {
+ if($className) $this->extraClasses = array($className);
+ $this->allowHTML = $allowHTML;
+
+ parent::__construct($name, $title, null, $form);
+ }
+
/**
* Function that returns whether this field contains data.
* Always returns false.
@@ -36,11 +57,17 @@ class DatalessField extends FormField {
}
/**
- * As DatalessFields are not initialized with an ID/name,
- * we keep the title for a unique reference.
+ * @param bool $bool
*/
- function Name() {
- return $this->title;
+ function setAllowHTML($bool) {
+ $this->allowHTML = $bool;
+ }
+
+ /**
+ * @return bool
+ */
+ function getAllowHTML() {
+ return $this->allowHTML;
}
}
?>
\ No newline at end of file
diff --git a/forms/HeaderField.php b/forms/HeaderField.php
index 509df0000..c21272d01 100755
--- a/forms/HeaderField.php
+++ b/forms/HeaderField.php
@@ -6,21 +6,41 @@
* @subpackage fields-dataless
*/
class HeaderField extends DatalessField {
- protected $headingLevel, $allowHTML;
- function __construct($title, $headingLevel = 2, $allowHTML = false, $form = null) {
+ /**
+ * @var int $headingLevel The level of the
to HTML tag. Default: 2
+ */
+ protected $headingLevel = 2;
+
+ function __construct($name, $title, $headingLevel = 2, $allowHTML = false, $form = null) {
+ // legacy handling for old parameters: $title, $heading, ...
+ // instead of new handling: $name, $title, $heading, ...
+ $args = func_get_args();
+ if(!isset($args[1]) || is_numeric($args[1])) {
+ $title = (isset($args[0])) ? $args[0] : null;
+ $name = $title; // this means i18nized fields won't be easily accessible through fieldByName()
+ $headingLevel = (isset($args[1])) ? $args[1] : null;
+ $allowHTML = (isset($args[2])) ? $args[2] : null;
+ $form = (isset($args[3])) ? $args[3] : null;
+ }
+
$this->headingLevel = $headingLevel;
$this->allowHTML = $allowHTML;
-
- parent::__construct(null, $title, null, $form);
+
+ parent::__construct($name, $title, null, $form);
}
+
function Field() {
- $XML_title = ($this->allowHTML) ? $this->title : Convert::raw2xml($this->title);
-
- // extraclass
- $XML_class = ($this->extraClass()) ? " class=\"{$this->extraClass()}\"" : '';
-
- return "headingLevel}{$XML_class}>$XML_titleheadingLevel>";
+ $attributes = array(
+ 'class' => $this->extraClass(),
+ 'id' => $this->id(),
+ 'name' => $this->Name(),
+ );
+ return $this->createTag(
+ "h{$this->headingLevel}",
+ $attributes,
+ ($this->getAllowHTML() ? $this->title : Convert::raw2xml($this->title))
+ );
}
}
?>
\ No newline at end of file
diff --git a/forms/LabelField.php b/forms/LabelField.php
index bfca0abb9..b6dcd0dbb 100755
--- a/forms/LabelField.php
+++ b/forms/LabelField.php
@@ -6,27 +6,46 @@
* @subpackage fields-dataless
*/
class LabelField extends DatalessField {
- protected $className;
- protected $allowHTML;
/**
- * Create a new label.
- * @param title The label itslef
- * @param class An HTML class to apply to the label.
+ * @param string $name
+ * @param string $title
+ * @param string $className (Deprecated: use addExtraClass())
+ * @param bool $allowHTML (Deprecated: use setAllowHTML())
+ * @param Form $form
*/
- function __construct($title, $className = "", $allowHTML = false, $form = null) {
- $this->className = $className;
+ function __construct($name, $title, $className = null, $allowHTML = false, $form = null) {
+ // legacy handling for old parameters: $title, $heading, ...
+ // instead of new handling: $name, $title, $heading, ...
+ $args = func_get_args();
+ if(!isset($args[1])) {
+ $title = (isset($args[0])) ? $args[0] : null;
+ $name = $title;
+ $classname = (isset($args[1])) ? $args[1] : null;
+ $allowHTML = (isset($args[2])) ? $args[2] : null;
+ $form = (isset($args[3])) ? $args[3] : null;
+ }
+
+ $this->headingLevel = $headingLevel;
$this->allowHTML = $allowHTML;
-
- parent::__construct(null, $title, null, $form);
+
+ parent::__construct($name, $title, null, $form);
}
/**
* Returns a label containing the title, and an HTML class if given.
*/
function Field() {
- $classClause = $this->className ? " class=\"$this->className\"" : '';
- return "";
+ $attributes = array(
+ 'class' => $this->extraClass(),
+ 'id' => $this->id(),
+ 'name' => $this->Name(),
+ );
+ return $this->createTag(
+ 'label',
+ $attributes,
+ ($this->getAllowHTML() ? $this->title : htmlentities($this->title))
+ );
}
}
?>
\ No newline at end of file
diff --git a/forms/LiteralField.php b/forms/LiteralField.php
index 51330bb08..408e2390c 100755
--- a/forms/LiteralField.php
+++ b/forms/LiteralField.php
@@ -1,32 +1,45 @@
content = $content;
+
+ parent::__construct($name);
}
+
function FieldHolder() {
return is_object($this->content) ? $this->content->forTemplate() : $this->content;
}
+
function Field() {
return $this->FieldHolder();
}
- /**
- * @desc Sets the content of this field to a new value
- */
- function setContent($content) {
- $this->content = $content;
- }
+ /**
+ * Sets the content of this field to a new value
+ * @param string $content
+ */
+ function setContent($content) {
+ $this->content = $content;
+ }
+
+ /**
+ * @return string
+ */
+ function getContent() {
+ return $this->content;
+ }
function performReadonlyTransformation() {
$this->setReadonly(true);