diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index b50bd1e28f..8dd96c3df1 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -3043,7 +3043,7 @@ celerity_register_resource_map(array( ), 'phabricator-hovercard' => array( - 'uri' => '/res/a6eafd28/rsrc/js/application/core/Hovercard.js', + 'uri' => '/res/345f3fca/rsrc/js/application/core/Hovercard.js', 'type' => 'js', 'requires' => array( diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f86e8a36f6..fd82a18d6c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1720,6 +1720,8 @@ phutil_register_library_map(array( 'celerity_generate_unique_node_id' => 'infrastructure/celerity/api.php', 'celerity_get_resource_uri' => 'infrastructure/celerity/api.php', 'celerity_register_resource_map' => 'infrastructure/celerity/map.php', + 'implode_handle_links' => 'applications/phid/handle/view/render.php', + 'implode_selected_handle_links' => 'applications/phid/handle/view/render.php', 'javelin_render_tag' => 'infrastructure/javelin/markup.php', 'javelin_tag' => 'infrastructure/javelin/markup.php', 'phabricator_date' => 'view/viewutils.php', diff --git a/src/applications/base/controller/PhabricatorController.php b/src/applications/base/controller/PhabricatorController.php index 85dcf05b48..fa6ce29a98 100644 --- a/src/applications/base/controller/PhabricatorController.php +++ b/src/applications/base/controller/PhabricatorController.php @@ -278,12 +278,9 @@ abstract class PhabricatorController extends AphrontController { throw new Exception("Unknown handle list style '{$style}'!"); } - $items = array(); - foreach ($phids as $phid) { - $items[] = $this->getHandle($phid)->renderLink(); - } - - return phutil_implode_html($style_map[$style], $items); + return implode_selected_handle_links($style_map[$style], + $this->getLoadedHandles(), + $phids); } protected function buildApplicationMenu() { diff --git a/src/applications/differential/field/specification/DifferentialFieldSpecification.php b/src/applications/differential/field/specification/DifferentialFieldSpecification.php index 6041f05763..d380e3215a 100644 --- a/src/applications/differential/field/specification/DifferentialFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialFieldSpecification.php @@ -277,13 +277,8 @@ abstract class DifferentialFieldSpecification { return phutil_tag('em', array(), pht('None')); } - $links = array(); - foreach ($user_phids as $user_phid) { - $handle = $this->getHandle($user_phid); - $links[] = $handle->renderLink(); - } - - return phutil_implode_html(', ', $links); + return implode_selected_handle_links(', ', + $this->getLoadedHandles(), $user_phids); } @@ -988,6 +983,14 @@ abstract class DifferentialFieldSpecification { return $this->handles[$phid]; } + final protected function getLoadedHandles() { + if ($this->handles === null) { + throw new DifferentialFieldDataNotAvailableException($this); + } + + return $this->handles; + } + /** * Get the list of properties for a diff set by @{method:setManualDiff}. * diff --git a/src/applications/maniphest/event/ManiphestHovercardEventListener.php b/src/applications/maniphest/event/ManiphestHovercardEventListener.php index 6be1d1d8d6..f65e568f15 100644 --- a/src/applications/maniphest/event/ManiphestHovercardEventListener.php +++ b/src/applications/maniphest/event/ManiphestHovercardEventListener.php @@ -60,7 +60,7 @@ final class ManiphestHovercardEventListener extends PhutilEventListener { $hovercard->addField(pht('Assigned to'), $owner); if ($project_phids) { $hovercard->addField(pht('Projects'), - $this->renderHandlesForPHIDs($project_phids, $viewer_handles)); + implode_selected_handle_links(', ', $viewer_handles, $project_phids)); } if ($edge_phids) { @@ -84,9 +84,8 @@ final class ManiphestHovercardEventListener extends PhutilEventListener { $hovercard->addField( $edge_name, - $this->renderHandlesForPHIDs( - array_keys($edges[$edge_type]), - $viewer_handles) + implode_selected_handle_links(', ', $viewer_handles, + array_keys($edges[$edge_type])) ->appendHTML($edge_overflow)); } } @@ -104,15 +103,4 @@ final class ManiphestHovercardEventListener extends PhutilEventListener { ->loadHandles(); } - protected function renderHandlesForPHIDs(array $phids, - array $handles, $glue = ', ') { - - $items = array(); - foreach ($phids as $phid) { - $items[] = $handles[$phid]->renderLink(); - } - - return phutil_implode_html($glue, $items); - } - } diff --git a/src/applications/phid/handle/view/render.php b/src/applications/phid/handle/view/render.php new file mode 100644 index 0000000000..6e19412c6a --- /dev/null +++ b/src/applications/phid/handle/view/render.php @@ -0,0 +1,35 @@ +renderLink(); + } + + return phutil_implode_html($glue, $items); +} + +/** + * Like @{function:implode_handle_links}Implodes selected handles from a pool of + * handles. Useful if you load handles for various phids, but only render a few + * of them at a time + * + * @group handle + * @return PhutilSafeHTML + */ +function implode_selected_handle_links($glue, array $handles, array $phids) { + + $items = array(); + foreach ($phids as $phid) { + $items[] = $handles[$phid]->renderLink(); + } + + return phutil_implode_html($glue, $items); +}