@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PHUITwoColumnView extends AphrontTagView {
4
5 private $mainColumn;
6 private $sideColumn = null;
7 private $navigation;
8 private $display;
9 private $fixed;
10 private $header;
11 private $subheader;
12 private $footer;
13 private $tabs;
14 private $propertySection = array();
15 private $curtain;
16
17 const DISPLAY_LEFT = 'phui-side-column-left';
18 const DISPLAY_RIGHT = 'phui-side-column-right';
19
20 public function setMainColumn($main) {
21 $this->mainColumn = $main;
22 return $this;
23 }
24
25 public function setSideColumn($side) {
26 $this->sideColumn = $side;
27 return $this;
28 }
29
30 public function setNavigation($nav) {
31 $this->navigation = $nav;
32 $this->display = self::DISPLAY_LEFT;
33 return $this;
34 }
35
36 public function setHeader(PHUIHeaderView $header) {
37 $this->header = $header;
38 return $this;
39 }
40
41 public function setSubheader($subheader) {
42 $this->subheader = $subheader;
43 return $this;
44 }
45
46 public function setTabs(PHUIListView $tabs) {
47 $tabs->setType(PHUIListView::TABBAR_LIST);
48 $this->tabs = $tabs;
49 return $this;
50 }
51
52 public function setFooter($footer) {
53 $this->footer = $footer;
54 return $this;
55 }
56
57 public function addPropertySection($title, $section) {
58 $this->propertySection[] = array(
59 'header' => $title,
60 'content' => $section,
61 );
62 return $this;
63 }
64
65 public function setCurtain(PHUICurtainView $curtain) {
66 $this->curtain = $curtain;
67 return $this;
68 }
69
70 public function getCurtain() {
71 return $this->curtain;
72 }
73
74 public function setFixed($fixed) {
75 $this->fixed = $fixed;
76 return $this;
77 }
78
79 public function setDisplay($display) {
80 $this->display = $display;
81 return $this;
82 }
83
84 private function getDisplay() {
85 if ($this->display) {
86 return $this->display;
87 } else {
88 return self::DISPLAY_RIGHT;
89 }
90 }
91
92 protected function getTagAttributes() {
93 $classes = array();
94 $classes[] = 'phui-two-column-view';
95 $classes[] = $this->getDisplay();
96
97 if ($this->fixed) {
98 $classes[] = 'phui-two-column-fixed';
99 }
100
101 if ($this->tabs) {
102 $classes[] = 'with-tabs';
103 }
104
105 if ($this->subheader) {
106 $classes[] = 'with-subheader';
107 }
108
109 if (!$this->header) {
110 $classes[] = 'without-header';
111 }
112
113 return array(
114 'class' => implode(' ', $classes),
115 );
116 }
117
118 protected function getTagContent() {
119 require_celerity_resource('phui-two-column-view-css');
120
121 $main = $this->buildMainColumn();
122 $side = $this->buildSideColumn();
123 $footer = $this->buildFooter();
124
125 $order = array($side, $main);
126
127 $inner = phutil_tag_div('phui-two-column-row grouped', $order);
128 $table = phutil_tag_div('phui-two-column-content', $inner);
129
130 $header = null;
131 if ($this->header) {
132 $curtain = $this->getCurtain();
133 if ($curtain) {
134 $action_list = $curtain->getActionList();
135 $this->header->setActionListID($action_list->getID());
136 }
137
138 $header = phutil_tag_div(
139 'phui-two-column-header', $this->header);
140 }
141
142 $tabs = null;
143 if ($this->tabs) {
144 $tabs = phutil_tag_div(
145 'phui-two-column-tabs', $this->tabs);
146 }
147
148 $subheader = null;
149 if ($this->subheader) {
150 $subheader = phutil_tag_div(
151 'phui-two-column-subheader', $this->subheader);
152 }
153
154 return phutil_tag(
155 'div',
156 array(
157 'class' => 'phui-two-column-container',
158 ),
159 array(
160 $header,
161 $tabs,
162 $subheader,
163 $table,
164 $footer,
165 ));
166 }
167
168 private function buildMainColumn() {
169
170 $view = array();
171 $sections = $this->propertySection;
172
173 if ($sections) {
174 foreach ($sections as $section) {
175 $section_header = $section['header'];
176
177 $section_content = $section['content'];
178 if ($section_content === null) {
179 continue;
180 }
181
182 if ($section_header instanceof PHUIHeaderView) {
183 $header = $section_header;
184 } else {
185 $header = id(new PHUIHeaderView())
186 ->setHeader($section_header);
187 }
188
189 $view[] = id(new PHUIObjectBoxView())
190 ->setHeader($header)
191 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
192 ->appendChild($section_content);
193 }
194 }
195
196 return phutil_tag(
197 'div',
198 array(
199 'class' => 'phui-main-column',
200 ),
201 array(
202 $view,
203 $this->mainColumn,
204 ));
205 }
206
207 private function buildSideColumn() {
208
209 $classes = array();
210 $classes[] = 'phui-side-column';
211 $navigation = null;
212 if ($this->navigation) {
213 $classes[] = 'side-has-nav';
214 $navigation = id(new PHUIObjectBoxView())
215 ->appendChild($this->navigation);
216 }
217
218 $curtain = $this->getCurtain();
219
220 return phutil_tag(
221 'div',
222 array(
223 'class' => implode(' ', $classes),
224 ),
225 array(
226 $navigation,
227 $curtain,
228 $this->sideColumn,
229 ));
230 }
231
232 private function buildFooter() {
233
234 $footer = $this->footer;
235
236 return phutil_tag(
237 'div',
238 array(
239 'class' => 'phui-two-column-content phui-two-column-footer',
240 ),
241 array(
242 $footer,
243 ));
244
245 }
246}