Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phid/view/PHUIHandleListView.php
<?php | <?php | ||||
/** | /** | ||||
* Convenience class for rendering a list of handles. | * Convenience class for rendering a list of handles. | ||||
* | * | ||||
* This class simplifies rendering a list of handles and improves loading and | * This class simplifies rendering a list of handles and improves loading and | ||||
* caching semantics in the rendering pipeline by delaying bulk loads until the | * caching semantics in the rendering pipeline by delaying bulk loads until the | ||||
* last possible moment. | * last possible moment. | ||||
*/ | */ | ||||
final class PHUIHandleListView | final class PHUIHandleListView | ||||
extends AphrontTagView { | extends AphrontTagView { | ||||
private $handleList; | private $handleList; | ||||
private $asInline; | private $asInline; | ||||
private $asText; | private $asText; | ||||
private $showStateIcons; | |||||
public function setHandleList(PhabricatorHandleList $list) { | public function setHandleList(PhabricatorHandleList $list) { | ||||
$this->handleList = $list; | $this->handleList = $list; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setAsInline($inline) { | public function setAsInline($inline) { | ||||
$this->asInline = $inline; | $this->asInline = $inline; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getAsInline() { | public function getAsInline() { | ||||
return $this->asInline; | return $this->asInline; | ||||
} | } | ||||
public function setAsText($as_text) { | public function setAsText($as_text) { | ||||
$this->asText = $as_text; | $this->asText = $as_text; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getAsText() { | public function getAsText() { | ||||
return $this->asText; | return $this->asText; | ||||
} | } | ||||
public function setShowStateIcons($show_state_icons) { | |||||
$this->showStateIcons = $show_state_icons; | |||||
return $this; | |||||
} | |||||
public function getShowStateIcons() { | |||||
return $this->showStateIcons; | |||||
} | |||||
protected function getTagName() { | protected function getTagName() { | ||||
if ($this->getAsText()) { | if ($this->getAsText()) { | ||||
return null; | return null; | ||||
} else { | } else { | ||||
// TODO: It would be nice to render this with a proper <ul />, at least | // TODO: It would be nice to render this with a proper <ul />, at least | ||||
// in block mode, but don't stir the waters up too much for now. | // in block mode, but don't stir the waters up too much for now. | ||||
return 'span'; | return 'span'; | ||||
} | } | ||||
} | } | ||||
protected function getTagContent() { | protected function getTagContent() { | ||||
$list = $this->handleList; | $list = $this->handleList; | ||||
$show_state_icons = $this->getShowStateIcons(); | |||||
$items = array(); | $items = array(); | ||||
foreach ($list as $handle) { | foreach ($list as $handle) { | ||||
$view = $list->renderHandle($handle->getPHID()) | $view = $list->renderHandle($handle->getPHID()) | ||||
->setShowHovercard(true) | ->setShowHovercard(true) | ||||
->setAsText($this->getAsText()); | ->setAsText($this->getAsText()); | ||||
if ($show_state_icons) { | |||||
$view->setShowStateIcon(true); | |||||
} | |||||
$items[] = $view; | $items[] = $view; | ||||
} | } | ||||
if ($this->getAsInline()) { | if ($this->getAsInline()) { | ||||
$items = phutil_implode_html(', ', $items); | $items = phutil_implode_html(', ', $items); | ||||
} else { | } else { | ||||
$items = phutil_implode_html(phutil_tag('br'), $items); | $items = phutil_implode_html(phutil_tag('br'), $items); | ||||
} | } | ||||
return $items; | return $items; | ||||
} | } | ||||
} | } |