Add a basic "harbormaster.step.edit" API method
[phabricator/blender.git] / src / view / AphrontTagView.php
bloba055fb16ad73fc6293bdca70b8037bc6d7085291
1 <?php
3 /**
4 * View which renders down to a single tag, and provides common access for tag
5 * attributes (setting classes, sigils, IDs, etc).
6 */
7 abstract class AphrontTagView extends AphrontView {
9 private $id;
10 private $classes = array();
11 private $sigils = array();
12 private $style;
13 private $metadata;
14 private $mustCapture;
15 private $workflow;
17 public function setWorkflow($workflow) {
18 $this->workflow = $workflow;
19 return $this;
22 public function getWorkflow() {
23 return $this->workflow;
26 public function setMustCapture($must_capture) {
27 $this->mustCapture = $must_capture;
28 return $this;
31 public function getMustCapture() {
32 return $this->mustCapture;
35 final public function setMetadata(array $metadata) {
36 $this->metadata = $metadata;
37 return $this;
40 final public function getMetadata() {
41 return $this->metadata;
44 final public function setStyle($style) {
45 $this->style = $style;
46 return $this;
49 final public function getStyle() {
50 return $this->style;
53 final public function addSigil($sigil) {
54 $this->sigils[] = $sigil;
55 return $this;
58 final public function getSigils() {
59 return $this->sigils;
62 public function addClass($class) {
63 $this->classes[] = $class;
64 return $this;
67 public function getClasses() {
68 return $this->classes;
71 public function setID($id) {
72 $this->id = $id;
73 return $this;
76 public function getID() {
77 return $this->id;
80 protected function getTagName() {
81 return 'div';
84 protected function getTagAttributes() {
85 return array();
88 protected function getTagContent() {
89 return $this->renderChildren();
92 final public function render() {
93 $this->willRender();
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);
117 throw new Exception(
118 pht("View '%s' did not return an array from getTagAttributes()!",
119 $class));
122 $sigils = $this->sigils;
123 if ($this->workflow) {
124 $sigils[] = 'workflow';
127 $tag_view_attributes = array(
128 'id' => $this->id,
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) {
140 continue;
142 if (!isset($attributes[$key])) {
143 $attributes[$key] = $value;
144 continue;
146 switch ($key) {
147 case 'class':
148 case 'sigil':
149 $attributes[$key] = $attributes[$key].' '.$value;
150 break;
151 default:
152 // Use the explicitly set value rather than the tag default value.
153 $attributes[$key] = $value;
154 break;
158 return javelin_tag(
159 $tag_name,
160 $attributes,
161 $this->getTagContent());