4 * View which renders down to a single tag, and provides common access for tag
5 * attributes (setting classes, sigils, IDs, etc).
7 abstract class AphrontTagView
extends AphrontView
{
10 private $classes = array();
11 private $sigils = array();
17 public function setWorkflow($workflow) {
18 $this->workflow
= $workflow;
22 public function getWorkflow() {
23 return $this->workflow
;
26 public function setMustCapture($must_capture) {
27 $this->mustCapture
= $must_capture;
31 public function getMustCapture() {
32 return $this->mustCapture
;
35 final public function setMetadata(array $metadata) {
36 $this->metadata
= $metadata;
40 final public function getMetadata() {
41 return $this->metadata
;
44 final public function setStyle($style) {
45 $this->style
= $style;
49 final public function getStyle() {
53 final public function addSigil($sigil) {
54 $this->sigils
[] = $sigil;
58 final public function getSigils() {
62 public function addClass($class) {
63 $this->classes
[] = $class;
67 public function getClasses() {
68 return $this->classes
;
71 public function setID($id) {
76 public function getID() {
80 protected function getTagName() {
84 protected function getTagAttributes() {
88 protected function getTagContent() {
89 return $this->renderChildren();
92 final public function render() {
95 // A tag view may render no tag at all. For example, the HandleListView is
96 // a container which renders a tag in HTML mode, but can also render in
97 // text mode without producing a tag. When a tag view has no tag name, just
98 // return the tag content as though the view did not exist.
99 $tag_name = $this->getTagName();
100 if ($tag_name === null) {
101 return $this->getTagContent();
104 $attributes = $this->getTagAttributes();
106 $implode = array('class', 'sigil');
107 foreach ($implode as $attr) {
108 if (isset($attributes[$attr])) {
109 if (is_array($attributes[$attr])) {
110 $attributes[$attr] = implode(' ', $attributes[$attr]);
115 if (!is_array($attributes)) {
116 $class = get_class($this);
118 pht("View '%s' did not return an array from getTagAttributes()!",
122 $sigils = $this->sigils
;
123 if ($this->workflow
) {
124 $sigils[] = 'workflow';
127 $tag_view_attributes = array(
130 'class' => implode(' ', $this->classes
),
131 'style' => $this->style
,
133 'meta' => $this->metadata
,
134 'sigil' => $sigils ?
implode(' ', $sigils) : null,
135 'mustcapture' => $this->mustCapture
,
138 foreach ($tag_view_attributes as $key => $value) {
139 if ($value === null) {
142 if (!isset($attributes[$key])) {
143 $attributes[$key] = $value;
149 $attributes[$key] = $attributes[$key].' '.$value;
152 // Use the explicitly set value rather than the tag default value.
153 $attributes[$key] = $value;
161 $this->getTagContent());