@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 PhabricatorActionListView extends AphrontTagView {
4
5 private $actions = array();
6 private $object;
7
8 public function setObject(PhabricatorLiskDAO $object) {
9 $this->object = $object;
10 return $this;
11 }
12
13 public function addAction(PhabricatorActionView $view) {
14 $this->actions[] = $view;
15 return $this;
16 }
17
18 protected function getTagName() {
19 if (!$this->actions) {
20 return null;
21 }
22
23 return 'ul';
24 }
25
26 protected function getTagAttributes() {
27 $classes = array();
28 $classes[] = 'phabricator-action-list-view';
29 return array(
30 'class' => implode(' ', $classes),
31 );
32 }
33
34 protected function getTagContent() {
35 $viewer = $this->getViewer();
36
37 $event = new PhabricatorEvent(
38 PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS,
39 array(
40 'object' => $this->object,
41 'actions' => $this->actions,
42 ));
43 $event->setUser($viewer);
44 PhutilEventEngine::dispatchEvent($event);
45
46 $actions = $event->getValue('actions');
47 if (!$actions) {
48 return null;
49 }
50
51 foreach ($actions as $action) {
52 $action->setViewer($viewer);
53 }
54
55 $sort = array();
56 foreach ($actions as $key => $action) {
57 $sort[$key] = id(new PhutilSortVector())
58 ->addInt($action->getOrder());
59 }
60 $sort = msortv($sort, 'getSelf');
61 $actions = array_select_keys($actions, array_keys($sort));
62
63 require_celerity_resource('phabricator-action-list-view-css');
64
65 $items = array();
66 foreach ($actions as $action) {
67 foreach ($action->getItems() as $item) {
68 $items[] = $item;
69 }
70 }
71
72 return $items;
73 }
74
75 public function getDropdownMenuMetadata() {
76 return array(
77 'items' => (string)hsprintf('%s', $this),
78 );
79 }
80
81
82}