PHUIHandleView.php 1.92 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php

/**
 * Convenience class for rendering a single handle.
 *
 * This class simplifies rendering a single handle, and improves loading and
 * caching semantics in the rendering pipeline by loading data at the last
 * moment.
 */

final class PHUIHandleView
  extends AphrontView {

  private $handleList;
  private $handlePHID;
16
  private $asTag;
17
  private $asText;
18
  private $useShortName;
19
  private $showHovercard;
20
  private $showStateIcon;
21 22 23 24 25 26 27 28 29 30 31

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

  public function setHandlePHID($phid) {
    $this->handlePHID = $phid;
    return $this;
  }

32 33 34 35 36
  public function setAsTag($tag) {
    $this->asTag = $tag;
    return $this;
  }

37 38 39 40 41
  public function setAsText($as_text) {
    $this->asText = $as_text;
    return $this;
  }

42 43 44 45 46
  public function setUseShortName($short) {
    $this->useShortName = $short;
    return $this;
  }

47 48 49 50 51
  public function setShowHovercard($hovercard) {
    $this->showHovercard = $hovercard;
    return $this;
  }

52 53 54 55 56 57 58 59 60
  public function setShowStateIcon($show_state_icon) {
    $this->showStateIcon = $show_state_icon;
    return $this;
  }

  public function getShowStateIcon() {
    return $this->showStateIcon;
  }

61
  public function render() {
62
    $handle = $this->handleList[$this->handlePHID];
63

64
    if ($this->asTag) {
65 66 67 68
      $tag = $handle->renderTag();

      if ($this->showHovercard) {
        $tag->setPHID($handle->getPHID());
69
      }
70 71

      return $tag;
72
    }
73

74 75 76 77
    if ($this->asText) {
      return $handle->getLinkName();
    }

78 79 80 81 82 83 84 85 86 87 88 89
    if ($this->useShortName) {
      $name = $handle->getName();
    } else {
      $name = null;
    }

    if ($this->showHovercard) {
      $link = $handle->renderHovercardLink($name);
    } else {
      $link = $handle->renderLink($name);
    }

90 91 92 93 94
    if ($this->showStateIcon) {
      $icon = $handle->renderStateIcon();
      $link = array($icon, ' ', $link);
    }

95
    return $link;
96 97 98
  }

}