|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Field that generates a heading tag. |
|
5
|
|
|
* |
|
6
|
|
|
* This can be used to add extra text in your forms. |
|
7
|
|
|
* |
|
8
|
|
|
* @package forms |
|
9
|
|
|
* @subpackage fields-dataless |
|
10
|
|
|
*/ |
|
11
|
|
|
class HeaderField extends DatalessField { |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* The level of the <h1> to <h6> HTML tag. |
|
15
|
|
|
* |
|
16
|
|
|
* @var int |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $headingLevel = 2; |
|
19
|
|
|
|
|
20
|
|
|
protected $schemaDataType = self::SCHEMA_DATA_TYPE_STRUCTURAL; |
|
21
|
|
|
|
|
22
|
|
|
protected $schemaComponent = 'HeaderField'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param string $name |
|
26
|
|
|
* @param string $title |
|
27
|
|
|
* @param int $headingLevel |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct($name, $title, $headingLevel = 2) { |
|
30
|
|
|
$this->setHeadingLevel($headingLevel); |
|
31
|
|
|
parent::__construct($name, $title); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @return int |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getHeadingLevel() { |
|
38
|
|
|
return $this->headingLevel; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param int $headingLevel |
|
43
|
|
|
* |
|
44
|
|
|
* @return $this |
|
45
|
|
|
*/ |
|
46
|
|
|
public function setHeadingLevel($headingLevel) { |
|
47
|
|
|
$this->headingLevel = $headingLevel; |
|
48
|
|
|
|
|
49
|
|
|
return $this; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getAttributes() { |
|
56
|
|
|
return array_merge( |
|
57
|
|
|
parent::getAttributes(), |
|
58
|
|
|
array( |
|
59
|
|
|
'id' => $this->ID(), |
|
60
|
|
|
'class' => $this->extraClass(), |
|
61
|
|
|
'type' => null, |
|
62
|
|
|
'name' => null |
|
63
|
|
|
) |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return null |
|
69
|
|
|
*/ |
|
70
|
|
|
public function Type() { |
|
71
|
|
|
return null; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Header fields support dynamic titles via schema state |
|
76
|
|
|
* |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getSchemaStateDefaults() { |
|
80
|
|
|
$state = parent::getSchemaStateDefaults(); |
|
81
|
|
|
|
|
82
|
|
|
$state['data']['title'] = $this->Title(); |
|
83
|
|
|
|
|
84
|
|
|
return $state; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Header fields heading level to be set |
|
89
|
|
|
* |
|
90
|
|
|
* @return array |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getSchemaDataDefaults() { |
|
93
|
|
|
$data = parent::getSchemaDataDefaults(); |
|
94
|
|
|
|
|
95
|
|
|
$data['data']['headingLevel'] = $this->headingLevel; |
|
96
|
|
|
|
|
97
|
|
|
return $data; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|