@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 HarbormasterBuildPlanEditEngine
4 extends PhabricatorEditEngine {
5
6 const ENGINECONST = 'harbormaster.buildplan';
7
8 public function isEngineConfigurable() {
9 return false;
10 }
11
12 public function getEngineName() {
13 return pht('Harbormaster Build Plans');
14 }
15
16 public function getSummaryHeader() {
17 return pht('Edit Harbormaster Build Plan Configurations');
18 }
19
20 public function getSummaryText() {
21 return pht('This engine is used to edit Harbormaster build plans.');
22 }
23
24 public function getEngineApplicationClass() {
25 return PhabricatorHarbormasterApplication::class;
26 }
27
28 protected function newEditableObject() {
29 $viewer = $this->getViewer();
30 return HarbormasterBuildPlan::initializeNewBuildPlan($viewer);
31 }
32
33 protected function newObjectQuery() {
34 return new HarbormasterBuildPlanQuery();
35 }
36
37 protected function getObjectCreateTitleText($object) {
38 return pht('Create Build Plan');
39 }
40
41 protected function getObjectCreateButtonText($object) {
42 return pht('Create Build Plan');
43 }
44
45 protected function getObjectEditTitleText($object) {
46 return pht('Edit Build Plan: %s', $object->getName());
47 }
48
49 protected function getObjectEditShortText($object) {
50 return pht('Edit Build Plan');
51 }
52
53 protected function getObjectCreateShortText() {
54 return pht('Create Build Plan');
55 }
56
57 protected function getObjectName() {
58 return pht('Build Plan');
59 }
60
61 protected function getEditorURI() {
62 return '/harbormaster/plan/edit/';
63 }
64
65 protected function getObjectCreateCancelURI($object) {
66 return '/harbormaster/plan/';
67 }
68
69 protected function getObjectViewURI($object) {
70 $id = $object->getID();
71 return "/harbormaster/plan/{$id}/";
72 }
73
74 protected function getCreateNewObjectPolicy() {
75 return $this->getApplication()->getPolicy(
76 HarbormasterCreatePlansCapability::CAPABILITY);
77 }
78
79 protected function buildCustomEditFields($object) {
80 $fields = array(
81 id(new PhabricatorTextEditField())
82 ->setKey('name')
83 ->setLabel(pht('Name'))
84 ->setIsRequired(true)
85 ->setTransactionType(
86 HarbormasterBuildPlanNameTransaction::TRANSACTIONTYPE)
87 ->setDescription(pht('The build plan name.'))
88 ->setConduitDescription(pht('Rename the plan.'))
89 ->setConduitTypeDescription(pht('New plan name.'))
90 ->setValue($object->getName()),
91 );
92
93
94 $metadata_key = HarbormasterBuildPlanBehavior::getTransactionMetadataKey();
95
96 $behaviors = HarbormasterBuildPlanBehavior::newPlanBehaviors();
97 foreach ($behaviors as $behavior) {
98 $key = $behavior->getKey();
99
100 // Get the raw key off the object so that we don't reset stuff to
101 // default values by mistake if a behavior goes missing somehow.
102 $storage_key = HarbormasterBuildPlanBehavior::getStorageKeyForBehaviorKey(
103 $key);
104 $behavior_option = $object->getPlanProperty($storage_key);
105
106 if (!phutil_nonempty_string($behavior_option)) {
107 $behavior_option = $behavior->getPlanOption($object)->getKey();
108 }
109
110 $fields[] = id(new PhabricatorSelectEditField())
111 ->setIsFormField(false)
112 ->setKey(sprintf('behavior.%s', $behavior->getKey()))
113 ->setMetadataValue($metadata_key, $behavior->getKey())
114 ->setLabel(pht('Behavior: %s', $behavior->getName()))
115 ->setTransactionType(
116 HarbormasterBuildPlanBehaviorTransaction::TRANSACTIONTYPE)
117 ->setValue($behavior_option)
118 ->setOptions($behavior->getOptionMap());
119 }
120
121 return $fields;
122 }
123
124}