diff --git a/src/applications/phid/view/PHUIHandleTagListView.php b/src/applications/phid/view/PHUIHandleTagListView.php index eb909d4b86..c4ef3762c3 100644 --- a/src/applications/phid/view/PHUIHandleTagListView.php +++ b/src/applications/phid/view/PHUIHandleTagListView.php @@ -1,123 +1,129 @@ handles = $handles; return $this; } public function setAnnotations(array $annotations) { $this->annotations = $annotations; return $this; } public function setLimit($limit) { $this->limit = $limit; return $this; } public function setNoDataString($no_data) { $this->noDataString = $no_data; return $this; } public function setSlim($slim) { $this->slim = true; return $this; } public function setShowHovercards($show_hovercards) { $this->showHovercards = $show_hovercards; return $this; } protected function getTagName() { return 'ul'; } protected function getTagAttributes() { return array( 'class' => 'phabricator-handle-tag-list', ); } protected function getTagContent() { $handles = $this->handles; // If the list is empty, we may render a "No Projects" tag. if (!count($handles)) { if (strlen($this->noDataString)) { $no_data_tag = $this->newPlaceholderTag() ->setName($this->noDataString); return $this->newItem($no_data_tag); } } - if ($this->limit && (count($handles) > $this->limit)) { - if (!is_array($handles)) { - $handles = iterator_to_array($handles); - } - $handles = array_slice($handles, 0, $this->limit); + // We may be passed a PhabricatorHandleList; if we are, convert it into + // a normal array. + if (!is_array($handles)) { + $handles = iterator_to_array($handles); + } + + $over_limit = $this->limit && (count($handles) > $this->limit); + if ($over_limit) { + $visible = array_slice($handles, 0, $this->limit); + } else { + $visible = $handles; } $list = array(); - foreach ($handles as $handle) { + foreach ($visible as $handle) { $tag = $handle->renderTag(); if ($this->showHovercards) { $tag->setPHID($handle->getPHID()); } if ($this->slim) { $tag->setSlimShady(true); } $list[] = $this->newItem( array( $tag, idx($this->annotations, $handle->getPHID(), null), )); } - if ($this->limit) { - if (count($this->handles) > $this->limit) { - $tip_text = implode(', ', mpull($this->handles, 'getName')); + if ($over_limit) { + $tip_text = implode(', ', mpull($handles, 'getName')); - $more = $this->newPlaceholderTag() - ->setName("\xE2\x80\xA6") - ->addSigil('has-tooltip') - ->setMetadata( - array( - 'tip' => $tip_text, - 'size' => 200, - )); + Javelin::initBehavior('phabricator-tooltips'); - $list[] = $this->newItem($more); - } + $more = $this->newPlaceholderTag() + ->setName("\xE2\x80\xA6") + ->addSigil('has-tooltip') + ->setMetadata( + array( + 'tip' => $tip_text, + 'size' => 200, + )); + + $list[] = $this->newItem($more); } return $list; } private function newItem($content) { return phutil_tag( 'li', array( 'class' => 'phabricator-handle-tag-list-item', ), $content); } private function newPlaceholderTag() { return id(new PHUITagView()) ->setType(PHUITagView::TYPE_OBJECT) ->setShade(PHUITagView::COLOR_DISABLED) ->setSlimShady($this->slim); } }