Path: blob/master/src/applications/almanac/editor/AlmanacServiceEditEngine.php
12256 views
<?php12final class AlmanacServiceEditEngine3extends PhabricatorEditEngine {45const ENGINECONST = 'almanac.service';67private $serviceType;89public function setServiceType($service_type) {10$this->serviceType = $service_type;11return $this;12}1314public function getServiceType() {15return $this->serviceType;16}1718public function isEngineConfigurable() {19return false;20}2122public function getEngineName() {23return pht('Almanac Services');24}2526public function getSummaryHeader() {27return pht('Edit Almanac Service Configurations');28}2930public function getSummaryText() {31return pht('This engine is used to edit Almanac services.');32}3334public function getEngineApplicationClass() {35return 'PhabricatorAlmanacApplication';36}3738protected function newEditableObject() {39$service_type = $this->getServiceType();40return AlmanacService::initializeNewService($service_type);41}4243protected function newEditableObjectFromConduit(array $raw_xactions) {44$type = null;45foreach ($raw_xactions as $raw_xaction) {46if ($raw_xaction['type'] !== 'type') {47continue;48}4950$type = $raw_xaction['value'];51}5253if ($type === null) {54throw new Exception(55pht(56'When creating a new Almanac service via the Conduit API, you '.57'must provide a "type" transaction to select a type.'));58}5960$map = AlmanacServiceType::getAllServiceTypes();61if (!isset($map[$type])) {62throw new Exception(63pht(64'Service type "%s" is unrecognized. Valid types are: %s.',65$type,66implode(', ', array_keys($map))));67}6869$this->setServiceType($type);7071return $this->newEditableObject();72}7374protected function newEditableObjectForDocumentation() {75$service_type = new AlmanacCustomServiceType();76$this->setServiceType($service_type->getServiceTypeConstant());77return $this->newEditableObject();78}7980protected function newObjectQuery() {81return id(new AlmanacServiceQuery())82->needProperties(true);83}8485protected function getObjectCreateTitleText($object) {86return pht('Create Service');87}8889protected function getObjectCreateButtonText($object) {90return pht('Create Service');91}9293protected function getObjectEditTitleText($object) {94return pht('Edit Service: %s', $object->getName());95}9697protected function getObjectEditShortText($object) {98return pht('Edit Service');99}100101protected function getObjectCreateShortText() {102return pht('Create Service');103}104105protected function getObjectName() {106return pht('Service');107}108109protected function getEditorURI() {110return '/almanac/service/edit/';111}112113protected function getObjectCreateCancelURI($object) {114return '/almanac/service/';115}116117protected function getObjectViewURI($object) {118return $object->getURI();119}120121protected function getCreateNewObjectPolicy() {122return $this->getApplication()->getPolicy(123AlmanacCreateServicesCapability::CAPABILITY);124}125126protected function buildCustomEditFields($object) {127return array(128id(new PhabricatorTextEditField())129->setKey('name')130->setLabel(pht('Name'))131->setDescription(pht('Name of the service.'))132->setTransactionType(AlmanacServiceNameTransaction::TRANSACTIONTYPE)133->setIsRequired(true)134->setValue($object->getName()),135id(new PhabricatorTextEditField())136->setKey('type')137->setLabel(pht('Type'))138->setIsFormField(false)139->setTransactionType(140AlmanacServiceTypeTransaction::TRANSACTIONTYPE)141->setDescription(pht('When creating a service, set the type.'))142->setConduitDescription(pht('Set the service type.'))143->setConduitTypeDescription(pht('Service type.'))144->setValue($object->getServiceType()),145);146}147148}149150151