Path: blob/master/src/view/phui/PHUIHovercardView.php
12249 views
<?php12/**3* The default one-for-all hovercard. We may derive from this one to create4* more specialized ones.5*/6final class PHUIHovercardView extends AphrontTagView {78/**9* @var PhabricatorObjectHandle10*/11private $handle;12private $object;1314private $title = array();15private $detail;16private $tags = array();17private $fields = array();18private $actions = array();19private $badges = array();20private $isExiled;2122public function setObjectHandle(PhabricatorObjectHandle $handle) {23$this->handle = $handle;24return $this;25}2627public function setObject($object) {28$this->object = $object;29return $this;30}3132public function getObject() {33return $this->object;34}3536public function setTitle($title) {37$this->title = $title;38return $this;39}4041public function setDetail($detail) {42$this->detail = $detail;43return $this;44}4546public function setIsExiled($is_exiled) {47$this->isExiled = $is_exiled;48return $this;49}5051public function getIsExiled() {52return $this->isExiled;53}5455public function addField($label, $value) {56$this->fields[] = array(57'label' => $label,58'value' => $value,59);60return $this;61}6263public function addAction($label, $uri, $workflow = false) {64$this->actions[] = array(65'label' => $label,66'uri' => $uri,67'workflow' => $workflow,68);69return $this;70}7172public function addTag(PHUITagView $tag) {73$this->tags[] = $tag;74return $this;75}7677public function addBadge(PHUIBadgeMiniView $badge) {78$this->badges[] = $badge;79return $this;80}8182protected function getTagAttributes() {83$classes = array();84$classes[] = 'phui-hovercard-wrapper';8586return array(87'class' => implode(' ', $classes),88);89}9091protected function getTagContent() {92if (!$this->handle) {93throw new PhutilInvalidStateException('setObjectHandle');94}9596$viewer = $this->getUser();97$handle = $this->handle;9899require_celerity_resource('phui-hovercard-view-css');100101// If we're a fully custom Hovercard, skip the common UI102$children = $this->renderChildren();103if ($children) {104return $children;105}106107$title = array(108id(new PHUISpacesNamespaceContextView())109->setUser($viewer)110->setObject($this->getObject()),111$this->title ? $this->title : $handle->getName(),112);113114$header = new PHUIHeaderView();115$header->setHeader($title);116if ($this->tags) {117foreach ($this->tags as $tag) {118$header->addActionItem($tag);119}120}121122$body = array();123124$body_title = null;125if ($this->detail) {126$body_title = $this->detail;127} else if (!$this->fields) {128// Fallback for object handles129$body_title = $handle->getFullName();130}131132if ($body_title) {133$body[] = phutil_tag_div('phui-hovercard-body-header', $body_title);134}135136foreach ($this->fields as $field) {137$item = array(138phutil_tag('strong', array(), $field['label']),139': ',140phutil_tag('span', array(), $field['value']),141);142$body[] = phutil_tag_div('phui-hovercard-body-item', $item);143}144145if ($this->badges) {146$badges = id(new PHUIBadgeBoxView())147->addItems($this->badges)148->setCollapsed(true);149$body[] = phutil_tag(150'div',151array(152'class' => 'phui-hovercard-body-item hovercard-badges',153),154$badges);155}156157if ($handle->getImageURI()) {158// Probably a user, we don't need to assume something else159// "Prepend" the image by appending $body160$body = phutil_tag(161'div',162array(163'class' => 'phui-hovercard-body-image',164),165phutil_tag(166'div',167array(168'class' => 'profile-header-picture-frame',169'style' => 'background-image: url('.$handle->getImageURI().');',170),171''))172->appendHTML(173phutil_tag(174'div',175array(176'class' => 'phui-hovercard-body-details',177),178$body));179}180181$buttons = array();182183foreach ($this->actions as $action) {184$options = array(185'class' => 'button button-grey',186'href' => $action['uri'],187);188189if ($action['workflow']) {190$options['sigil'] = 'workflow';191$buttons[] = javelin_tag(192'a',193$options,194$action['label']);195} else {196$buttons[] = phutil_tag(197'a',198$options,199$action['label']);200}201}202203$tail = null;204if ($buttons) {205$tail = phutil_tag_div('phui-hovercard-tail', $buttons);206}207208$hovercard = phutil_tag_div(209'phui-hovercard-container grouped',210array(211phutil_tag_div('phui-hovercard-head', $header),212phutil_tag_div('phui-hovercard-body grouped', $body),213$tail,214));215216return $hovercard;217}218219}220221222