PHUIHandleListView.php 1.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php

/**
 * Convenience class for rendering a list of handles.
 *
 * This class simplifies rendering a list of handles and improves loading and
 * caching semantics in the rendering pipeline by delaying bulk loads until the
 * last possible moment.
 */
final class PHUIHandleListView
  extends AphrontTagView {

  private $handleList;
14
  private $asInline;
15
  private $asText;
16
  private $showStateIcons;
17 18 19 20 21 22

  public function setHandleList(PhabricatorHandleList $list) {
    $this->handleList = $list;
    return $this;
  }

23 24
  public function setAsInline($inline) {
    $this->asInline = $inline;
25 26 27
    return $this;
  }

28 29
  public function getAsInline() {
    return $this->asInline;
30 31
  }

32 33 34 35 36 37 38 39 40
  public function setAsText($as_text) {
    $this->asText = $as_text;
    return $this;
  }

  public function getAsText() {
    return $this->asText;
  }

41 42 43 44 45 46 47 48 49
  public function setShowStateIcons($show_state_icons) {
    $this->showStateIcons = $show_state_icons;
    return $this;
  }

  public function getShowStateIcons() {
    return $this->showStateIcons;
  }

50
  protected function getTagName() {
51 52 53 54 55 56 57
    if ($this->getAsText()) {
      return null;
    } else {
      // 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.
      return 'span';
    }
58 59 60
  }

  protected function getTagContent() {
61
    $list = $this->handleList;
62 63 64

    $show_state_icons = $this->getShowStateIcons();

65
    $items = array();
66
    foreach ($list as $handle) {
67 68 69
      $view = $list->renderHandle($handle->getPHID())
        ->setShowHovercard(true)
        ->setAsText($this->getAsText());
70

71 72 73 74
      if ($show_state_icons) {
        $view->setShowStateIcon(true);
      }

75
      $items[] = $view;
76 77
    }

78
    if ($this->getAsInline()) {
79 80 81 82 83 84 85 86 87
      $items = phutil_implode_html(', ', $items);
    } else {
      $items = phutil_implode_html(phutil_tag('br'), $items);
    }

    return $items;
  }

}