Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / view / phui / PHUIInfoView.php
blob91d89afe410dbdcd38ec1418a78178664c7227bd
1 <?php
3 final class PHUIInfoView extends AphrontTagView {
5 const SEVERITY_ERROR = 'error';
6 const SEVERITY_WARNING = 'warning';
7 const SEVERITY_NOTICE = 'notice';
8 const SEVERITY_NODATA = 'nodata';
9 const SEVERITY_SUCCESS = 'success';
10 const SEVERITY_PLAIN = 'plain';
11 const SEVERITY_MFA = 'mfa';
13 private $title;
14 private $errors = array();
15 private $severity = null;
16 private $id;
17 private $buttons = array();
18 private $isHidden;
19 private $flush;
20 private $icon;
22 public function setTitle($title) {
23 $this->title = $title;
24 return $this;
27 public function setSeverity($severity) {
28 $this->severity = $severity;
29 return $this;
32 private function getSeverity() {
33 $severity = $this->severity ? $this->severity : self::SEVERITY_ERROR;
34 return $severity;
37 public function setErrors(array $errors) {
38 $this->errors = $errors;
39 return $this;
42 public function setID($id) {
43 $this->id = $id;
44 return $this;
47 public function setIsHidden($is_hidden) {
48 $this->isHidden = $is_hidden;
49 return $this;
52 public function setFlush($flush) {
53 $this->flush = $flush;
54 return $this;
57 public function setIcon($icon) {
58 if ($icon instanceof PHUIIconView) {
59 $this->icon = $icon;
60 } else {
61 $icon = id(new PHUIIconView())
62 ->setIcon($icon);
63 $this->icon = $icon;
66 return $this;
69 private function getIcon() {
70 if ($this->icon) {
71 return $this->icon;
74 switch ($this->getSeverity()) {
75 case self::SEVERITY_ERROR:
76 $icon = 'fa-exclamation-circle';
77 break;
78 case self::SEVERITY_WARNING:
79 $icon = 'fa-exclamation-triangle';
80 break;
81 case self::SEVERITY_NOTICE:
82 $icon = 'fa-info-circle';
83 break;
84 case self::SEVERITY_PLAIN:
85 case self::SEVERITY_NODATA:
86 return null;
87 case self::SEVERITY_SUCCESS:
88 $icon = 'fa-check-circle';
89 break;
90 case self::SEVERITY_MFA:
91 $icon = 'fa-lock';
92 break;
95 $icon = id(new PHUIIconView())
96 ->setIcon($icon)
97 ->addClass('phui-info-icon');
98 return $icon;
101 public function addButton(PHUIButtonView $button) {
102 $this->buttons[] = $button;
103 return $this;
106 protected function getTagAttributes() {
107 $classes = array();
108 $classes[] = 'phui-info-view';
109 $classes[] = 'phui-info-severity-'.$this->getSeverity();
110 $classes[] = 'grouped';
111 if ($this->flush) {
112 $classes[] = 'phui-info-view-flush';
114 if ($this->getIcon()) {
115 $classes[] = 'phui-info-has-icon';
118 return array(
119 'id' => $this->id,
120 'class' => implode(' ', $classes),
121 'style' => $this->isHidden ? 'display: none;' : null,
125 protected function getTagContent() {
126 require_celerity_resource('phui-info-view-css');
128 $errors = $this->errors;
129 if (count($errors) > 1) {
130 $list = array();
131 foreach ($errors as $error) {
132 $list[] = phutil_tag(
133 'li',
134 array(),
135 $error);
137 $list = phutil_tag(
138 'ul',
139 array(
140 'class' => 'phui-info-view-list',
142 $list);
143 } else if (count($errors) == 1) {
144 $list = head($this->errors);
145 } else {
146 $list = null;
149 $title = $this->title;
150 if ($title !== null && strlen($title)) {
151 $title = phutil_tag(
152 'h1',
153 array(
154 'class' => 'phui-info-view-head',
156 $title);
157 } else {
158 $title = null;
161 $children = $this->renderChildren();
162 if ($list) {
163 $children[] = $list;
166 $body = null;
167 if (!empty($children)) {
168 $body = phutil_tag(
169 'div',
170 array(
171 'class' => 'phui-info-view-body',
173 $children);
176 $buttons = null;
177 if (!empty($this->buttons)) {
178 $buttons = phutil_tag(
179 'div',
180 array(
181 'class' => 'phui-info-view-actions',
183 $this->buttons);
186 $icon = null;
187 if ($this->getIcon()) {
188 $icon = phutil_tag(
189 'div',
190 array(
191 'class' => 'phui-info-view-icon',
193 $this->getIcon());
196 return array(
197 $icon,
198 $buttons,
199 $title,
200 $body,