Changeset View
Changeset View
Standalone View
Standalone View
src/view/phui/PHUIHovercardView.php
| <?php | <?php | ||||
| /** | /** | ||||
| * The default one-for-all hovercard. We may derive from this one to create | * The default one-for-all hovercard. We may derive from this one to create | ||||
| * more specialized ones. | * more specialized ones. | ||||
| */ | */ | ||||
| final class PHUIHovercardView extends AphrontView { | final class PHUIHovercardView extends AphrontTagView { | ||||
| /** | /** | ||||
| * @var PhabricatorObjectHandle | * @var PhabricatorObjectHandle | ||||
| */ | */ | ||||
| private $handle; | private $handle; | ||||
| private $object; | private $object; | ||||
| private $title = array(); | private $title = array(); | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | public function addTag(PHUITagView $tag) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function addBadge(PHUIBadgeMiniView $badge) { | public function addBadge(PHUIBadgeMiniView $badge) { | ||||
| $this->badges[] = $badge; | $this->badges[] = $badge; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function render() { | protected function getTagAttributes() { | ||||
| $classes = array(); | |||||
| $classes[] = 'phui-hovercard-wrapper'; | |||||
| return array( | |||||
| 'class' => implode(' ', $classes), | |||||
| ); | |||||
| } | |||||
| protected function getTagContent() { | |||||
| if (!$this->handle) { | if (!$this->handle) { | ||||
| throw new PhutilInvalidStateException('setObjectHandle'); | throw new PhutilInvalidStateException('setObjectHandle'); | ||||
| } | } | ||||
| $viewer = $this->getUser(); | $viewer = $this->getUser(); | ||||
| $handle = $this->handle; | $handle = $this->handle; | ||||
| require_celerity_resource('phui-hovercard-view-css'); | require_celerity_resource('phui-hovercard-view-css'); | ||||
| // If we're a fully custom Hovercard, skip the common UI | |||||
| $children = $this->renderChildren(); | |||||
| if ($children) { | |||||
| return $children; | |||||
| } | |||||
| $title = array( | $title = array( | ||||
| id(new PHUISpacesNamespaceContextView()) | id(new PHUISpacesNamespaceContextView()) | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setObject($this->getObject()), | ->setObject($this->getObject()), | ||||
| pht( | $this->title ? $this->title : $handle->getName(), | ||||
| '%s: %s', | |||||
| $handle->getTypeName(), | |||||
| $this->title ? $this->title : $handle->getName()), | |||||
| ); | ); | ||||
| $header = new PHUIHeaderView(); | $header = new PHUIHeaderView(); | ||||
| $header->setHeader($title); | $header->setHeader($title); | ||||
| if ($this->tags) { | if ($this->tags) { | ||||
| foreach ($this->tags as $tag) { | foreach ($this->tags as $tag) { | ||||
| $header->addTag($tag); | $header->addTag($tag); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | protected function getTagContent() { | ||||
| } | } | ||||
| $tail = null; | $tail = null; | ||||
| if ($buttons) { | if ($buttons) { | ||||
| $tail = phutil_tag_div('phui-hovercard-tail', $buttons); | $tail = phutil_tag_div('phui-hovercard-tail', $buttons); | ||||
| } | } | ||||
| $hovercard = phutil_tag_div( | $hovercard = phutil_tag_div( | ||||
| 'phui-hovercard-container', | 'phui-hovercard-container grouped', | ||||
| array( | array( | ||||
| phutil_tag_div('phui-hovercard-head', $header), | phutil_tag_div('phui-hovercard-head', $header), | ||||
| phutil_tag_div('phui-hovercard-body grouped', $body), | phutil_tag_div('phui-hovercard-body grouped', $body), | ||||
| $tail, | $tail, | ||||
| )); | )); | ||||
| return phutil_tag_div('phui-hovercard-wrapper', $hovercard); | return $hovercard; | ||||
| } | } | ||||
| } | } | ||||