3 final class PhabricatorSearchHovercardController
4 extends PhabricatorSearchBaseController
{
6 public function shouldAllowPublic() {
10 public function handleRequest(AphrontRequest
$request) {
11 $viewer = $this->getViewer();
13 $cards = $request->getJSONMap('cards');
15 // If object names are provided, look them up and pretend they were
16 // passed as additional PHIDs. This is primarily useful for debugging,
17 // since you don't have to go look up user PHIDs to preview their
19 $names = $request->getStrList('names');
21 $named_objects = id(new PhabricatorObjectQuery())
26 foreach ($named_objects as $object) {
28 'objectPHID' => $object->getPHID(),
33 $object_phids = array();
34 $handle_phids = array();
35 $context_phids = array();
36 foreach ($cards as $card) {
37 $object_phid = idx($card, 'objectPHID');
39 $handle_phids[] = $object_phid;
40 $object_phids[] = $object_phid;
42 $context_phid = idx($card, 'contextPHID');
45 $object_phids[] = $context_phid;
46 $context_phids[] = $context_phid;
50 $handles = id(new PhabricatorHandleQuery())
52 ->withPHIDs($handle_phids)
55 $objects = id(new PhabricatorObjectQuery())
57 ->withPHIDs($object_phids)
59 $objects = mpull($objects, null, 'getPHID');
61 $context_objects = array_select_keys($objects, $context_phids);
63 if ($context_objects) {
64 PhabricatorPolicyFilterSet
::loadHandleViewCapabilities(
71 PhabricatorHovercardEngineExtension
::getAllEnabledExtensions();
73 $extension_maps = array();
74 foreach ($extensions as $extension_key => $extension) {
75 $extension->setViewer($viewer);
77 $extension_phids = array();
78 foreach ($objects as $phid => $object) {
79 if ($extension->canRenderObjectHovercard($object)) {
80 $extension_phids[$phid] = $phid;
84 $extension_maps[$extension_key] = $extension_phids;
87 $extension_data = array();
88 foreach ($extensions as $extension_key => $extension) {
89 $extension_phids = $extension_maps[$extension_key];
90 if (!$extension_phids) {
91 unset($extensions[$extension_key]);
95 $extension_data[$extension_key] = $extension->willRenderHovercards(
96 array_select_keys($objects, $extension_phids));
100 foreach ($cards as $card_key => $card) {
101 $object_phid = $card['objectPHID'];
103 $handle = $handles[$object_phid];
104 $object = idx($objects, $object_phid);
106 $context_phid = idx($card, 'contextPHID');
108 $context_object = idx($context_objects, $context_phid);
110 $context_object = null;
113 $hovercard = id(new PHUIHovercardView())
115 ->setObjectHandle($handle);
117 if ($context_object) {
118 if ($handle->hasCapabilities()) {
119 if (!$handle->hasViewCapability($context_object)) {
120 $hovercard->setIsExiled(true);
126 $hovercard->setObject($object);
128 foreach ($extension_maps as $extension_key => $extension_phids) {
129 if (isset($extension_phids[$object_phid])) {
130 $extensions[$extension_key]->renderHovercard(
134 $extension_data[$extension_key]);
139 $results[$card_key] = $hovercard;
142 if ($request->isAjax()) {
143 return id(new AphrontAjaxResponse())->setContent(
149 foreach ($results as $result_key => $hovercard) {
150 $results[$result_key] = phutil_tag('div',
157 return $this->newPage()
158 ->appendChild($results)
159 ->setShowFooter(false);