@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
at recaptime-dev/main 220 lines 5.0 kB view raw
1<?php 2 3/** 4 * The default one-for-all hovercard. We may derive from this one to create 5 * more specialized ones. 6 */ 7final class PHUIHovercardView extends AphrontTagView { 8 9 /** 10 * @var PhabricatorObjectHandle 11 */ 12 private $handle; 13 private $object; 14 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; 22 23 public function setObjectHandle(PhabricatorObjectHandle $handle) { 24 $this->handle = $handle; 25 return $this; 26 } 27 28 public function setObject($object) { 29 $this->object = $object; 30 return $this; 31 } 32 33 public function getObject() { 34 return $this->object; 35 } 36 37 public function setTitle($title) { 38 $this->title = $title; 39 return $this; 40 } 41 42 public function setDetail($detail) { 43 $this->detail = $detail; 44 return $this; 45 } 46 47 public function setIsExiled($is_exiled) { 48 $this->isExiled = $is_exiled; 49 return $this; 50 } 51 52 public function getIsExiled() { 53 return $this->isExiled; 54 } 55 56 public function addField($label, $value) { 57 $this->fields[] = array( 58 'label' => $label, 59 'value' => $value, 60 ); 61 return $this; 62 } 63 64 public function addAction($label, $uri, $workflow = false) { 65 $this->actions[] = array( 66 'label' => $label, 67 'uri' => $uri, 68 'workflow' => $workflow, 69 ); 70 return $this; 71 } 72 73 public function addTag(PHUITagView $tag) { 74 $this->tags[] = $tag; 75 return $this; 76 } 77 78 public function addBadge(PHUIBadgeMiniView $badge) { 79 $this->badges[] = $badge; 80 return $this; 81 } 82 83 protected function getTagAttributes() { 84 $classes = array(); 85 $classes[] = 'phui-hovercard-wrapper'; 86 87 return array( 88 'class' => implode(' ', $classes), 89 ); 90 } 91 92 protected function getTagContent() { 93 if (!$this->handle) { 94 throw new PhutilInvalidStateException('setObjectHandle'); 95 } 96 97 $viewer = $this->getUser(); 98 $handle = $this->handle; 99 100 require_celerity_resource('phui-hovercard-view-css'); 101 102 // If we're a fully custom Hovercard, skip the common UI 103 $children = $this->renderChildren(); 104 if ($children) { 105 return $children; 106 } 107 108 $title = array( 109 id(new PHUISpacesNamespaceContextView()) 110 ->setUser($viewer) 111 ->setObject($this->getObject()), 112 $this->title ? $this->title : $handle->getName(), 113 ); 114 115 $header = new PHUIHeaderView(); 116 $header->setHeader($title); 117 if ($this->tags) { 118 foreach ($this->tags as $tag) { 119 $header->addActionItem($tag); 120 } 121 } 122 123 $body = array(); 124 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(); 131 } 132 133 if ($body_title) { 134 $body[] = phutil_tag_div('phui-hovercard-body-header', $body_title); 135 } 136 137 foreach ($this->fields as $field) { 138 $item = array( 139 phutil_tag('strong', array(), $field['label']), 140 ': ', 141 phutil_tag('span', array(), $field['value']), 142 ); 143 $body[] = phutil_tag_div('phui-hovercard-body-item', $item); 144 } 145 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', 154 ), 155 $badges); 156 } 157 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', 165 ), 166 phutil_tag( 167 'div', 168 array( 169 'class' => 'profile-header-picture-frame', 170 'style' => 'background-image: url('.$handle->getImageURI().');', 171 ), 172 '')) 173 ->appendHTML( 174 phutil_tag( 175 'div', 176 array( 177 'class' => 'phui-hovercard-body-details', 178 ), 179 $body)); 180 } 181 182 $buttons = array(); 183 184 foreach ($this->actions as $action) { 185 $options = array( 186 'class' => 'button button-grey', 187 'href' => $action['uri'], 188 ); 189 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']); 201 } 202 } 203 204 $tail = null; 205 if ($buttons) { 206 $tail = phutil_tag_div('phui-hovercard-tail', $buttons); 207 } 208 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, 215 )); 216 217 return $hovercard; 218 } 219 220}