silverstripe-framework/forms/HeaderField.php

85 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2015-04-27 23:05:44 +02:00
/**
* 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 {
/**
2015-04-27 23:05:44 +02:00
* The level of the <h1> to <h6> HTML tag.
*
* @var int
*/
protected $headingLevel = 2;
2015-04-27 23:05:44 +02:00
/**
* @param string $name
* @param null|string $title
* @param int $headingLevel
*/
public function __construct($name, $title = null, $headingLevel = 2) {
2015-04-27 23:05:44 +02:00
// legacy handling:
// $title, $headingLevel...
$args = func_get_args();
2015-04-27 23:05:44 +02:00
if(!isset($args[1]) || is_numeric($args[1])) {
2015-04-27 23:05:44 +02:00
if(isset($args[0])) {
$title = $args[0];
}
// Prefix name to avoid collisions.
$name = 'HeaderField' . $title;
2015-04-27 23:05:44 +02:00
if(isset($args[1])) {
$headingLevel = $args[1];
}
}
$this->setHeadingLevel($headingLevel);
parent::__construct($name, $title);
}
2015-04-27 23:05:44 +02:00
/**
* @return int
*/
public function getHeadingLevel() {
return $this->headingLevel;
}
2015-04-27 23:05:44 +02:00
/**
* @param int $headingLevel
*
* @return $this
*/
public function setHeadingLevel($headingLevel) {
$this->headingLevel = $headingLevel;
return $this;
}
2015-04-27 23:05:44 +02:00
/**
* {@inheritdoc}
*/
public function getAttributes() {
return array_merge(
2015-04-27 23:05:44 +02:00
parent::getAttributes(),
array(
'id' => $this->ID(),
2015-04-27 23:05:44 +02:00
'class' => $this->extraClass(),
)
);
}
2015-04-27 23:05:44 +02:00
/**
* @return null
*/
public function Type() {
return null;
}
}