diff --git a/forms/HeaderField.php b/forms/HeaderField.php index 971a498d3..4bea26157 100644 --- a/forms/HeaderField.php +++ b/forms/HeaderField.php @@ -1,4 +1,5 @@ to
HTML tag. Default: 2 + * The level of the

to

HTML tag. + * + * @var int */ protected $headingLevel = 2; - + + /** + * @param string $name + * @param null|string $title + * @param int $headingLevel + */ public function __construct($name, $title = null, $headingLevel = 2) { - // legacy handling for old parameters: $title, $heading, ... - // instead of new handling: $name, $title, $heading, ... + // legacy handling: + // $title, $headingLevel... $args = func_get_args(); + if(!isset($args[1]) || is_numeric($args[1])) { - $title = (isset($args[0])) ? $args[0] : null; - // 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. - // this means i18nized fields won't be easily accessible through fieldByName() + if(isset($args[0])) { + $title = $args[0]; + } + + // Prefix name to avoid collisions. $name = 'HeaderField' . $title; - $headingLevel = (isset($args[1])) ? $args[1] : null; - $form = (isset($args[3])) ? $args[3] : null; - } - - if($headingLevel) $this->headingLevel = $headingLevel; - + + if(isset($args[1])) { + $headingLevel = $args[1]; + } + } + + $this->setHeadingLevel($headingLevel); + parent::__construct($name, $title); } + /** + * @return int + */ public function getHeadingLevel() { return $this->headingLevel; } - - public function setHeadingLevel($level) { - $this->headingLevel = $level; + + /** + * @param int $headingLevel + * + * @return $this + */ + public function setHeadingLevel($headingLevel) { + $this->headingLevel = $headingLevel; + return $this; } + /** + * {@inheritdoc} + */ public function getAttributes() { return array_merge( + parent::getAttributes(), array( 'id' => $this->ID(), - 'class' => $this->extraClass() - ), - $this->attributes + 'class' => $this->extraClass(), + ) ); } + /** + * @return null + */ public function Type() { return null; } - }