Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / view / phui / PHUIHovercardView.php
blob6b85364ceb78ed205e3acbe8eab806e3e5ba69d4
1 <?php
3 /**
4 * The default one-for-all hovercard. We may derive from this one to create
5 * more specialized ones.
6 */
7 final class PHUIHovercardView extends AphrontTagView {
9 /**
10 * @var PhabricatorObjectHandle
12 private $handle;
13 private $object;
15 private $title = array();
16 private $detail;
17 private $tags = array();
18 private $fields = array();
19 private $actions = array();
20 private $badges = array();
21 private $isExiled;
23 public function setObjectHandle(PhabricatorObjectHandle $handle) {
24 $this->handle = $handle;
25 return $this;
28 public function setObject($object) {
29 $this->object = $object;
30 return $this;
33 public function getObject() {
34 return $this->object;
37 public function setTitle($title) {
38 $this->title = $title;
39 return $this;
42 public function setDetail($detail) {
43 $this->detail = $detail;
44 return $this;
47 public function setIsExiled($is_exiled) {
48 $this->isExiled = $is_exiled;
49 return $this;
52 public function getIsExiled() {
53 return $this->isExiled;
56 public function addField($label, $value) {
57 $this->fields[] = array(
58 'label' => $label,
59 'value' => $value,
61 return $this;
64 public function addAction($label, $uri, $workflow = false) {
65 $this->actions[] = array(
66 'label' => $label,
67 'uri' => $uri,
68 'workflow' => $workflow,
70 return $this;
73 public function addTag(PHUITagView $tag) {
74 $this->tags[] = $tag;
75 return $this;
78 public function addBadge(PHUIBadgeMiniView $badge) {
79 $this->badges[] = $badge;
80 return $this;
83 protected function getTagAttributes() {
84 $classes = array();
85 $classes[] = 'phui-hovercard-wrapper';
87 return array(
88 'class' => implode(' ', $classes),
92 protected function getTagContent() {
93 if (!$this->handle) {
94 throw new PhutilInvalidStateException('setObjectHandle');
97 $viewer = $this->getUser();
98 $handle = $this->handle;
100 require_celerity_resource('phui-hovercard-view-css');
102 // If we're a fully custom Hovercard, skip the common UI
103 $children = $this->renderChildren();
104 if ($children) {
105 return $children;
108 $title = array(
109 id(new PHUISpacesNamespaceContextView())
110 ->setUser($viewer)
111 ->setObject($this->getObject()),
112 $this->title ? $this->title : $handle->getName(),
115 $header = new PHUIHeaderView();
116 $header->setHeader($title);
117 if ($this->tags) {
118 foreach ($this->tags as $tag) {
119 $header->addActionItem($tag);
123 $body = array();
125 $body_title = null;
126 if ($this->detail) {
127 $body_title = $this->detail;
128 } else if (!$this->fields) {
129 // Fallback for object handles
130 $body_title = $handle->getFullName();
133 if ($body_title) {
134 $body[] = phutil_tag_div('phui-hovercard-body-header', $body_title);
137 foreach ($this->fields as $field) {
138 $item = array(
139 phutil_tag('strong', array(), $field['label']),
140 ': ',
141 phutil_tag('span', array(), $field['value']),
143 $body[] = phutil_tag_div('phui-hovercard-body-item', $item);
146 if ($this->badges) {
147 $badges = id(new PHUIBadgeBoxView())
148 ->addItems($this->badges)
149 ->setCollapsed(true);
150 $body[] = phutil_tag(
151 'div',
152 array(
153 'class' => 'phui-hovercard-body-item hovercard-badges',
155 $badges);
158 if ($handle->getImageURI()) {
159 // Probably a user, we don't need to assume something else
160 // "Prepend" the image by appending $body
161 $body = phutil_tag(
162 'div',
163 array(
164 'class' => 'phui-hovercard-body-image',
166 phutil_tag(
167 'div',
168 array(
169 'class' => 'profile-header-picture-frame',
170 'style' => 'background-image: url('.$handle->getImageURI().');',
172 ''))
173 ->appendHTML(
174 phutil_tag(
175 'div',
176 array(
177 'class' => 'phui-hovercard-body-details',
179 $body));
182 $buttons = array();
184 foreach ($this->actions as $action) {
185 $options = array(
186 'class' => 'button button-grey',
187 'href' => $action['uri'],
190 if ($action['workflow']) {
191 $options['sigil'] = 'workflow';
192 $buttons[] = javelin_tag(
193 'a',
194 $options,
195 $action['label']);
196 } else {
197 $buttons[] = phutil_tag(
198 'a',
199 $options,
200 $action['label']);
204 $tail = null;
205 if ($buttons) {
206 $tail = phutil_tag_div('phui-hovercard-tail', $buttons);
209 $hovercard = phutil_tag_div(
210 'phui-hovercard-container grouped',
211 array(
212 phutil_tag_div('phui-hovercard-head', $header),
213 phutil_tag_div('phui-hovercard-body grouped', $body),
214 $tail,
217 return $hovercard;