Clean up HeaderField

This commit is contained in:
Christopher Pitt 2015-04-28 09:05:44 +12:00
parent 72ee96cd65
commit 05c2d04b42

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Field that generates a heading tag. * Field that generates a heading tag.
* *
@ -8,52 +9,76 @@
* @subpackage fields-dataless * @subpackage fields-dataless
*/ */
class HeaderField extends DatalessField { class HeaderField extends DatalessField {
/** /**
* @var int $headingLevel The level of the <h1> to <h6> HTML tag. Default: 2 * The level of the <h1> to <h6> HTML tag.
*
* @var int
*/ */
protected $headingLevel = 2; protected $headingLevel = 2;
/**
* @param string $name
* @param null|string $title
* @param int $headingLevel
*/
public function __construct($name, $title = null, $headingLevel = 2) { public function __construct($name, $title = null, $headingLevel = 2) {
// legacy handling for old parameters: $title, $heading, ... // legacy handling:
// instead of new handling: $name, $title, $heading, ... // $title, $headingLevel...
$args = func_get_args(); $args = func_get_args();
if(!isset($args[1]) || is_numeric($args[1])) { if(!isset($args[1]) || is_numeric($args[1])) {
$title = (isset($args[0])) ? $args[0] : null; if(isset($args[0])) {
// Use "HeaderField(title)" as the default field name for a HeaderField; if it's just set to title then we $title = $args[0];
// risk causing accidental duplicate-field creation. }
// this means i18nized fields won't be easily accessible through fieldByName()
// Prefix name to avoid collisions.
$name = 'HeaderField' . $title; $name = 'HeaderField' . $title;
$headingLevel = (isset($args[1])) ? $args[1] : null;
$form = (isset($args[3])) ? $args[3] : null; if(isset($args[1])) {
} $headingLevel = $args[1];
}
if($headingLevel) $this->headingLevel = $headingLevel; }
$this->setHeadingLevel($headingLevel);
parent::__construct($name, $title); parent::__construct($name, $title);
} }
/**
* @return int
*/
public function getHeadingLevel() { public function getHeadingLevel() {
return $this->headingLevel; return $this->headingLevel;
} }
public function setHeadingLevel($level) { /**
$this->headingLevel = $level; * @param int $headingLevel
*
* @return $this
*/
public function setHeadingLevel($headingLevel) {
$this->headingLevel = $headingLevel;
return $this; return $this;
} }
/**
* {@inheritdoc}
*/
public function getAttributes() { public function getAttributes() {
return array_merge( return array_merge(
parent::getAttributes(),
array( array(
'id' => $this->ID(), 'id' => $this->ID(),
'class' => $this->extraClass() 'class' => $this->extraClass(),
), )
$this->attributes
); );
} }
/**
* @return null
*/
public function Type() { public function Type() {
return null; return null;
} }
} }