This repository was archived by the owner on Mar 30, 2022. It is now read-only.
forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAphrontTagView.php
154 lines (125 loc) · 3.18 KB
/
AphrontTagView.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* View which renders down to a single tag, and provides common access for tag
* attributes (setting classes, sigils, IDs, etc).
*/
abstract class AphrontTagView extends AphrontView {
private $id;
private $classes = array();
private $sigils = array();
private $style;
private $metadata;
private $mustCapture;
private $workflow;
public function setWorkflow($workflow) {
$this->workflow = $workflow;
return $this;
}
public function getWorkflow() {
return $this->workflow;
}
public function setMustCapture($must_capture) {
$this->mustCapture = $must_capture;
return $this;
}
public function getMustCapture() {
return $this->mustCapture;
}
final public function setMetadata(array $metadata) {
$this->metadata = $metadata;
return $this;
}
final public function getMetadata() {
return $this->metadata;
}
final public function setStyle($style) {
$this->style = $style;
return $this;
}
final public function getStyle() {
return $this->style;
}
final public function addSigil($sigil) {
$this->sigils[] = $sigil;
return $this;
}
final public function getSigils() {
return $this->sigils;
}
public function addClass($class) {
$this->classes[] = $class;
return $this;
}
public function getClasses() {
return $this->classes;
}
public function setID($id) {
$this->id = $id;
return $this;
}
public function getID() {
return $this->id;
}
protected function getTagName() {
return 'div';
}
protected function getTagAttributes() {
return array();
}
protected function getTagContent() {
return $this->renderChildren();
}
final public function render() {
$this->willRender();
$attributes = $this->getTagAttributes();
$implode = array('class', 'sigil');
foreach ($implode as $attr) {
if (isset($attributes[$attr])) {
if (is_array($attributes[$attr])) {
$attributes[$attr] = implode(' ', $attributes[$attr]);
}
}
}
if (!is_array($attributes)) {
$class = get_class($this);
throw new Exception(
pht("View '%s' did not return an array from getTagAttributes()!",
$class));
}
$sigils = $this->sigils;
if ($this->workflow) {
$sigils[] = 'workflow';
}
$tag_view_attributes = array(
'id' => $this->id,
'class' => implode(' ', $this->classes),
'style' => $this->style,
'meta' => $this->metadata,
'sigil' => $sigils ? implode(' ', $sigils) : null,
'mustcapture' => $this->mustCapture,
);
foreach ($tag_view_attributes as $key => $value) {
if ($value === null) {
continue;
}
if (!isset($attributes[$key])) {
$attributes[$key] = $value;
continue;
}
switch ($key) {
case 'class':
case 'sigil':
$attributes[$key] = $attributes[$key].' '.$value;
break;
default:
// Use the explicitly set value rather than the tag default value.
$attributes[$key] = $value;
break;
}
}
return javelin_tag(
$this->getTagName(),
$attributes,
$this->getTagContent());
}
}