@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
at recaptime-dev/main 149 lines 3.9 kB view raw
1<?php 2 3final class AlmanacServiceEditEngine 4 extends PhabricatorEditEngine { 5 6 const ENGINECONST = 'almanac.service'; 7 8 private $serviceType; 9 10 public function setServiceType($service_type) { 11 $this->serviceType = $service_type; 12 return $this; 13 } 14 15 public function getServiceType() { 16 return $this->serviceType; 17 } 18 19 public function isEngineConfigurable() { 20 return false; 21 } 22 23 public function getEngineName() { 24 return pht('Almanac Services'); 25 } 26 27 public function getSummaryHeader() { 28 return pht('Edit Almanac Service Configurations'); 29 } 30 31 public function getSummaryText() { 32 return pht('This engine is used to edit Almanac services.'); 33 } 34 35 public function getEngineApplicationClass() { 36 return PhabricatorAlmanacApplication::class; 37 } 38 39 protected function newEditableObject() { 40 $service_type = $this->getServiceType(); 41 return AlmanacService::initializeNewService($service_type); 42 } 43 44 protected function newEditableObjectFromConduit(array $raw_xactions) { 45 $type = null; 46 foreach ($raw_xactions as $raw_xaction) { 47 if ($raw_xaction['type'] !== 'type') { 48 continue; 49 } 50 51 $type = $raw_xaction['value']; 52 } 53 54 if ($type === null) { 55 throw new Exception( 56 pht( 57 'When creating a new Almanac service via the Conduit API, you '. 58 'must provide a "type" transaction to select a type.')); 59 } 60 61 $map = AlmanacServiceType::getAllServiceTypes(); 62 if (!isset($map[$type])) { 63 throw new Exception( 64 pht( 65 'Service type "%s" is unrecognized. Valid types are: %s.', 66 $type, 67 implode(', ', array_keys($map)))); 68 } 69 70 $this->setServiceType($type); 71 72 return $this->newEditableObject(); 73 } 74 75 protected function newEditableObjectForDocumentation() { 76 $service_type = new AlmanacCustomServiceType(); 77 $this->setServiceType($service_type->getServiceTypeConstant()); 78 return $this->newEditableObject(); 79 } 80 81 protected function newObjectQuery() { 82 return id(new AlmanacServiceQuery()) 83 ->needProperties(true); 84 } 85 86 protected function getObjectCreateTitleText($object) { 87 return pht('Create Service'); 88 } 89 90 protected function getObjectCreateButtonText($object) { 91 return pht('Create Service'); 92 } 93 94 protected function getObjectEditTitleText($object) { 95 return pht('Edit Service: %s', $object->getName()); 96 } 97 98 protected function getObjectEditShortText($object) { 99 return pht('Edit Service'); 100 } 101 102 protected function getObjectCreateShortText() { 103 return pht('Create Service'); 104 } 105 106 protected function getObjectName() { 107 return pht('Service'); 108 } 109 110 protected function getEditorURI() { 111 return '/almanac/service/edit/'; 112 } 113 114 protected function getObjectCreateCancelURI($object) { 115 return '/almanac/service/'; 116 } 117 118 protected function getObjectViewURI($object) { 119 return $object->getURI(); 120 } 121 122 protected function getCreateNewObjectPolicy() { 123 return $this->getApplication()->getPolicy( 124 AlmanacCreateServicesCapability::CAPABILITY); 125 } 126 127 protected function buildCustomEditFields($object) { 128 return array( 129 id(new PhabricatorTextEditField()) 130 ->setKey('name') 131 ->setLabel(pht('Name')) 132 ->setDescription(pht('Name of the service.')) 133 ->setTransactionType(AlmanacServiceNameTransaction::TRANSACTIONTYPE) 134 ->setIsRequired(true) 135 ->setValue($object->getName()), 136 id(new PhabricatorTextEditField()) 137 ->setKey('type') 138 ->setLabel(pht('Type')) 139 ->setIsFormField(false) 140 ->setTransactionType( 141 AlmanacServiceTypeTransaction::TRANSACTIONTYPE) 142 ->setDescription(pht('When creating a service, set the type.')) 143 ->setConduitDescription(pht('Set the service type.')) 144 ->setConduitTypeDescription(pht('Service type.')) 145 ->setValue($object->getServiceType()), 146 ); 147 } 148 149}