2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Field that generates a heading tag.
|
2012-04-14 07:32:29 +02:00
|
|
|
*
|
2007-07-19 12:40:28 +02:00
|
|
|
* This can be used to add extra text in your forms.
|
2012-04-14 07:32:29 +02:00
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-dataless
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class HeaderField extends DatalessField {
|
|
|
|
|
2008-10-16 15:26:25 +02:00
|
|
|
/**
|
|
|
|
* @var int $headingLevel The level of the <h1> to <h6> HTML tag. Default: 2
|
|
|
|
*/
|
|
|
|
protected $headingLevel = 2;
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __construct($name, $title = null, $headingLevel = 2) {
|
2008-10-16 15:26:25 +02:00
|
|
|
// 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;
|
2009-01-08 00:00:54 +01:00
|
|
|
// Use "HeaderField(title)" as the default field name for a HeaderField; if it's just set to title then we risk
|
|
|
|
// causing accidental duplicate-field creation.
|
|
|
|
$name = 'HeaderField' . $title; // this means i18nized fields won't be easily accessible through fieldByName()
|
2008-10-16 15:26:25 +02:00
|
|
|
$headingLevel = (isset($args[1])) ? $args[1] : null;
|
|
|
|
$form = (isset($args[3])) ? $args[3] : null;
|
|
|
|
}
|
|
|
|
|
2008-12-04 23:38:32 +01:00
|
|
|
if($headingLevel) $this->headingLevel = $headingLevel;
|
2008-10-16 15:26:25 +02:00
|
|
|
|
2012-01-02 17:09:30 +01:00
|
|
|
parent::__construct($name, $title);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
|
|
|
public function getHeadingLevel() {
|
|
|
|
return $this->headingLevel;
|
|
|
|
}
|
2012-04-03 07:05:21 +02:00
|
|
|
|
|
|
|
public function setHeadingLevel($level) {
|
|
|
|
$this->headingLevel = $level;
|
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getAttributes() {
|
2011-12-22 13:10:57 +01:00
|
|
|
return array_merge(
|
|
|
|
array(
|
|
|
|
'id' => $this->ID(),
|
|
|
|
'class' => $this->extraClass()
|
|
|
|
),
|
|
|
|
$this->attributes
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Type() {
|
2011-12-22 13:10:57 +01:00
|
|
|
return null;
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
|
|
|
|
}
|