@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 PhabricatorObjectRelationship extends Phobject {
4
5 private $viewer;
6 private $contentSource;
7
8 public function setViewer(PhabricatorUser $viewer) {
9 $this->viewer = $viewer;
10 return $this;
11 }
12
13 public function getViewer() {
14 return $this->viewer;
15 }
16
17 public function setContentSource(PhabricatorContentSource $content_source) {
18 $this->contentSource = $content_source;
19 return $this;
20 }
21
22 public function getContentSource() {
23 return $this->contentSource;
24 }
25
26 final public function getRelationshipConstant() {
27 return $this->getPhobjectClassConstant('RELATIONSHIPKEY');
28 }
29
30 abstract public function isEnabledForObject($object);
31
32 abstract public function getEdgeConstant();
33
34 /**
35 * @return string
36 */
37 abstract protected function getActionName();
38
39 /**
40 * @return string
41 */
42 abstract protected function getActionIcon();
43
44 /**
45 * @return bool
46 */
47 abstract public function canRelateObjects($src, $dst);
48
49 /**
50 * @return string
51 */
52 abstract public function getDialogTitleText();
53
54 /**
55 * @return string
56 */
57 abstract public function getDialogHeaderText();
58
59 /**
60 * @return string
61 */
62 abstract public function getDialogButtonText();
63
64 /**
65 * Display additional instructions at the bottom of the dialog
66 * @return string|null
67 */
68 public function getDialogInstructionsText() {
69 return null;
70 }
71
72 /**
73 * Whether to list the relationship action as a menu item in the
74 * "Edit Related Objects" menu in the object's side column
75 *
76 * @return bool
77 */
78 public function shouldAppearInActionMenu() {
79 return true;
80 }
81
82 protected function isActionEnabled($object) {
83 $viewer = $this->getViewer();
84
85 return PhabricatorPolicyFilter::hasCapability(
86 $viewer,
87 $object,
88 PhabricatorPolicyCapability::CAN_EDIT);
89 }
90
91 public function getRequiredRelationshipCapabilities() {
92 return array(
93 PhabricatorPolicyCapability::CAN_VIEW,
94 );
95 }
96
97 final public function newSource() {
98 $viewer = $this->getViewer();
99
100 return $this->newRelationshipSource()
101 ->setViewer($viewer);
102 }
103
104 abstract protected function newRelationshipSource();
105
106 final public function getSourceURI($object) {
107 $relationship_key = $this->getRelationshipConstant();
108 $object_phid = $object->getPHID();
109
110 return "/search/source/{$relationship_key}/{$object_phid}/";
111 }
112
113 final public function newAction($object) {
114 $is_enabled = $this->isActionEnabled($object);
115 $action_uri = $this->getActionURI($object);
116
117 return id(new PhabricatorActionView())
118 ->setName($this->getActionName())
119 ->setHref($action_uri)
120 ->setIcon($this->getActionIcon())
121 ->setDisabled(!$is_enabled)
122 ->setWorkflow(true);
123 }
124
125 final public static function getAllRelationships() {
126 return id(new PhutilClassMapQuery())
127 ->setAncestorClass(self::class)
128 ->setUniqueMethod('getRelationshipConstant')
129 ->execute();
130 }
131
132 private function getActionURI($object) {
133 $phid = $object->getPHID();
134 $type = $this->getRelationshipConstant();
135 return "/search/rel/{$type}/{$phid}/";
136 }
137
138 public function getMaximumSelectionSize() {
139 return null;
140 }
141
142 public function canUndoRelationship() {
143 return true;
144 }
145
146 public function willUpdateRelationships($object, array $add, array $rem) {
147 return array();
148 }
149
150 public function didUpdateRelationships($object, array $add, array $rem) {
151 return;
152 }
153
154}