Skip to content

Commit 4d175ac

Browse files
author
epriestley
committedAug 19, 2016
Simplify how tag lists manage their handles
Summary: Fixes T11493. This code is a little bit weird/clever, simplify it so that we always cast the handles to an array early on. Test Plan: {F1767668} Reviewers: chad Reviewed By: chad Maniphest Tasks: T11493 Differential Revision: https://secure.phabricator.com/D16422
1 parent e7aa874 commit 4d175ac

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed
 

‎src/applications/phid/view/PHUIHandleTagListView.php

+25-19
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,21 @@ protected function getTagContent() {
6161
}
6262
}
6363

64-
if ($this->limit && (count($handles) > $this->limit)) {
65-
if (!is_array($handles)) {
66-
$handles = iterator_to_array($handles);
67-
}
68-
$handles = array_slice($handles, 0, $this->limit);
64+
// We may be passed a PhabricatorHandleList; if we are, convert it into
65+
// a normal array.
66+
if (!is_array($handles)) {
67+
$handles = iterator_to_array($handles);
68+
}
69+
70+
$over_limit = $this->limit && (count($handles) > $this->limit);
71+
if ($over_limit) {
72+
$visible = array_slice($handles, 0, $this->limit);
73+
} else {
74+
$visible = $handles;
6975
}
7076

7177
$list = array();
72-
foreach ($handles as $handle) {
78+
foreach ($visible as $handle) {
7379
$tag = $handle->renderTag();
7480
if ($this->showHovercards) {
7581
$tag->setPHID($handle->getPHID());
@@ -84,21 +90,21 @@ protected function getTagContent() {
8490
));
8591
}
8692

87-
if ($this->limit) {
88-
if (count($this->handles) > $this->limit) {
89-
$tip_text = implode(', ', mpull($this->handles, 'getName'));
93+
if ($over_limit) {
94+
$tip_text = implode(', ', mpull($handles, 'getName'));
9095

91-
$more = $this->newPlaceholderTag()
92-
->setName("\xE2\x80\xA6")
93-
->addSigil('has-tooltip')
94-
->setMetadata(
95-
array(
96-
'tip' => $tip_text,
97-
'size' => 200,
98-
));
96+
Javelin::initBehavior('phabricator-tooltips');
9997

100-
$list[] = $this->newItem($more);
101-
}
98+
$more = $this->newPlaceholderTag()
99+
->setName("\xE2\x80\xA6")
100+
->addSigil('has-tooltip')
101+
->setMetadata(
102+
array(
103+
'tip' => $tip_text,
104+
'size' => 200,
105+
));
106+
107+
$list[] = $this->newItem($more);
102108
}
103109

104110
return $list;

0 commit comments

Comments
 (0)
Failed to load comments.