2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2015-04-27 23:05:44 +02:00
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
namespace SilverStripe\Forms;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
class HeaderField extends DatalessField
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The level of the <h1> to <h6> HTML tag.
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $headingLevel = 2;
|
|
|
|
|
|
|
|
protected $schemaDataType = self::SCHEMA_DATA_TYPE_STRUCTURAL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @skipUpgrade
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $schemaComponent = 'HeaderField';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @param string $title
|
|
|
|
* @param int $headingLevel
|
|
|
|
*/
|
|
|
|
public function __construct($name, $title, $headingLevel = 2)
|
|
|
|
{
|
|
|
|
$this->setHeadingLevel($headingLevel);
|
|
|
|
parent::__construct($name, $title);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getHeadingLevel()
|
|
|
|
{
|
|
|
|
return $this->headingLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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(),
|
|
|
|
'type' => null,
|
|
|
|
'name' => null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|