@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
3abstract class PhabricatorIconSet
4 extends Phobject {
5
6 abstract protected function newIcons();
7
8 final public function getIconSetKey() {
9 return $this->getPhobjectClassConstant('ICONSETKEY');
10 }
11
12 public function getChooseButtonText() {
13 return pht('Choose Icon...');
14 }
15
16 public function getSelectIconTitleText() {
17 return pht('Choose Icon');
18 }
19
20 public function getSelectURI() {
21 $key = $this->getIconSetKey();
22 return "/file/iconset/{$key}/select/";
23 }
24
25 final public function getIcons() {
26 $icons = $this->newIcons();
27
28 // TODO: Validate icons.
29 $icons = mpull($icons, null, 'getKey');
30
31 return $icons;
32 }
33
34 final public function getIcon($key) {
35 $icons = $this->getIcons();
36 return idx($icons, $key);
37 }
38
39 final public function getIconLabel($key) {
40 $icon = $this->getIcon($key);
41
42 if ($icon) {
43 return $icon->getLabel();
44 }
45
46 return $key;
47 }
48
49 final public function renderIconForControl(PhabricatorIconSetIcon $icon) {
50 return phutil_tag(
51 'span',
52 array(),
53 array(
54 id(new PHUIIconView())->setIcon($icon->getIcon()),
55 ' ',
56 $icon->getLabel(),
57 ));
58 }
59
60 final public static function getIconSetByKey($key) {
61 $sets = self::getAllIconSets();
62 return idx($sets, $key);
63 }
64
65 final public static function getAllIconSets() {
66 return id(new PhutilClassMapQuery())
67 ->setAncestorClass(self::class)
68 ->setUniqueMethod('getIconSetKey')
69 ->execute();
70 }
71
72}