silverstripe-framework/Forms/HeaderField.php

103 lines
1.7 KiB
PHP
Raw Normal View History

<?php
2015-04-27 23:05:44 +02:00
namespace SilverStripe\Forms;
/**
* Field that generates a heading tag.
*
* This can be used to add extra text in your forms.
*/
class HeaderField extends DatalessField {
2014-08-15 08:53:05 +02:00
/**
2015-04-27 23:05:44 +02:00
* The level of the <h1> to <h6> HTML tag.
*
* @var int
*/
protected $headingLevel = 2;
2014-08-15 08:53:05 +02:00
protected $schemaDataType = self::SCHEMA_DATA_TYPE_STRUCTURAL;
/**
* @skipUpgrade
* @var string
*/
protected $schemaComponent = 'HeaderField';
2015-04-27 23:05:44 +02:00
/**
* @param string $name
* @param string $title
2015-04-27 23:05:44 +02:00
* @param int $headingLevel
*/
public function __construct($name, $title, $headingLevel = 2) {
2015-04-27 23:05:44 +02:00
$this->setHeadingLevel($headingLevel);
parent::__construct($name, $title);
}
2015-04-27 23:05:44 +02:00
/**
* @return int
*/
public function getHeadingLevel() {
return $this->headingLevel;
}
2014-08-15 08:53:05 +02:00
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(),
'type' => null,
'name' => null
2015-04-27 23:05:44 +02:00
)
);
}
2015-04-27 23:05:44 +02:00
/**
* @return null
*/
public function Type() {
return null;
}
/**
* Header fields support dynamic titles via schema state
*
* @return array
*/
public function getSchemaStateDefaults() {
$state = parent::getSchemaStateDefaults();
$state['data']['title'] = $this->Title();
return $state;
}
/**
* Header fields heading level to be set
*
* @return array
*/
public function getSchemaDataDefaults() {
$data = parent::getSchemaDataDefaults();
$data['data']['headingLevel'] = $this->headingLevel;
return $data;
}
}