@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PHUIFormIconSetControl
4 extends AphrontFormControl {
5
6 private $iconSet;
7
8 public function setIconSet(PhabricatorIconSet $icon_set) {
9 $this->iconSet = $icon_set;
10 return $this;
11 }
12
13 public function getIconSet() {
14 return $this->iconSet;
15 }
16
17 protected function getCustomControlClass() {
18 return 'phui-form-iconset-control';
19 }
20
21 protected function renderInput() {
22 Javelin::initBehavior('choose-control');
23
24 $set = $this->getIconSet();
25
26 $input_id = celerity_generate_unique_node_id();
27 $display_id = celerity_generate_unique_node_id();
28
29 $is_disabled = $this->getDisabled();
30
31 $classes = array();
32 $classes[] = 'button';
33 $classes[] = 'button-grey';
34
35 if ($is_disabled) {
36 $classes[] = 'disabled';
37 }
38
39 $button = javelin_tag(
40 'a',
41 array(
42 'href' => '#',
43 'class' => implode(' ', $classes),
44 'sigil' => 'phui-form-iconset-button',
45 ),
46 $set->getChooseButtonText());
47
48 $icon = $set->getIcon($this->getValue());
49 if ($icon) {
50 $display = $set->renderIconForControl($icon);
51 } else {
52 $display = null;
53 }
54
55 $display_cell = phutil_tag(
56 'td',
57 array(
58 'class' => 'phui-form-iconset-display-cell',
59 'id' => $display_id,
60 ),
61 $display);
62
63 $button_cell = phutil_tag(
64 'td',
65 array(
66 'class' => 'phui-form-iconset-button-cell',
67 ),
68 $button);
69
70 $row = phutil_tag(
71 'tr',
72 array(),
73 array($display_cell, $button_cell));
74
75 $layout = javelin_tag(
76 'table',
77 array(
78 'class' => 'phui-form-iconset-table',
79 'sigil' => 'phui-form-iconset',
80 'meta' => array(
81 'uri' => $set->getSelectURI(),
82 'inputID' => $input_id,
83 'displayID' => $display_id,
84 ),
85 ),
86 $row);
87
88 $hidden_input = phutil_tag(
89 'input',
90 array(
91 'type' => 'hidden',
92 'disabled' => ($is_disabled ? 'disabled' : null),
93 'name' => $this->getName(),
94 'value' => $this->getValue(),
95 'id' => $input_id,
96 ));
97
98 return array(
99 $hidden_input,
100 $layout,
101 );
102 }
103
104}