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.
|
|
|
|
*/
|
|
|
|
class HeaderField extends DatalessField {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-10-16 15:26:25 +02:00
|
|
|
/**
|
2015-04-27 23:05:44 +02:00
|
|
|
* The level of the <h1> to <h6> HTML tag.
|
|
|
|
*
|
|
|
|
* @var int
|
2008-10-16 15:26:25 +02:00
|
|
|
*/
|
|
|
|
protected $headingLevel = 2;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-08-11 05:32:00 +02:00
|
|
|
protected $schemaDataType = self::SCHEMA_DATA_TYPE_STRUCTURAL;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
/**
|
|
|
|
* @skipUpgrade
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-08-11 05:32:00 +02:00
|
|
|
protected $schemaComponent = 'HeaderField';
|
|
|
|
|
2015-04-27 23:05:44 +02:00
|
|
|
/**
|
|
|
|
* @param string $name
|
2016-08-11 05:32:00 +02:00
|
|
|
* @param string $title
|
2015-04-27 23:05:44 +02:00
|
|
|
* @param int $headingLevel
|
|
|
|
*/
|
2016-08-11 05:32:00 +02:00
|
|
|
public function __construct($name, $title, $headingLevel = 2) {
|
2015-04-27 23:05:44 +02:00
|
|
|
$this->setHeadingLevel($headingLevel);
|
2012-01-02 17:09:30 +01:00
|
|
|
parent::__construct($name, $title);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2015-04-27 23:05:44 +02:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
2011-03-23 05:12:25 +01:00
|
|
|
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;
|
|
|
|
|
2013-11-02 01:21:56 +01:00
|
|
|
return $this;
|
2012-04-03 07:05:21 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2015-04-27 23:05:44 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getAttributes() {
|
2011-12-22 13:10:57 +01:00
|
|
|
return array_merge(
|
2015-04-27 23:05:44 +02:00
|
|
|
parent::getAttributes(),
|
2011-12-22 13:10:57 +01:00
|
|
|
array(
|
|
|
|
'id' => $this->ID(),
|
2015-04-27 23:05:44 +02:00
|
|
|
'class' => $this->extraClass(),
|
2016-04-25 23:45:52 +02:00
|
|
|
'type' => null,
|
|
|
|
'name' => null
|
2015-04-27 23:05:44 +02:00
|
|
|
)
|
2011-12-22 13:10:57 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-27 23:05:44 +02:00
|
|
|
/**
|
|
|
|
* @return null
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Type() {
|
2011-12-22 13:10:57 +01:00
|
|
|
return null;
|
|
|
|
}
|
2016-08-11 05:32:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
}
|