silverstripe-framework/forms/HeaderField.php
Ingo Schommer e95c5657ff API CHANGE Changed constructor parameters for LabelField and Header: First parameter is now $name, not $title. Necessary change to consistently support labelled fields which can be identified and modified within a FieldSet, and in the DOM structure. Both HeaderField and LabelField still acceppt old notation through checking the parameter signature with func_get_args().
API CHANGE Moved setAllowHTML() to DataLessField
ENHANCEMENT Using createTag() to create HeaderField and LabelField, which adds support for HTML id attributes and extra css classes through addExtraClass()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64421 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-10-16 13:26:25 +00:00

46 lines
1.3 KiB
PHP
Executable File

<?php
/**
* Field that generates a heading tag.
* This can be used to add extra text in your forms.
* @package forms
* @subpackage fields-dataless
*/
class HeaderField extends DatalessField {
/**
* @var int $headingLevel The level of the <h1> to <h6> 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($name, $title, null, $form);
}
function Field() {
$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))
);
}
}
?>