Path: blob/master/src/applications/almanac/editor/AlmanacBindingEditEngine.php
12256 views
<?php12final class AlmanacBindingEditEngine3extends PhabricatorEditEngine {45const ENGINECONST = 'almanac.binding';67private $service;89public function setService(AlmanacService $service) {10$this->service = $service;11return $this;12}1314public function getService() {15if (!$this->service) {16throw new PhutilInvalidStateException('setService');17}18return $this->service;19}2021public function isEngineConfigurable() {22return false;23}2425public function getEngineName() {26return pht('Almanac Bindings');27}2829public function getSummaryHeader() {30return pht('Edit Almanac Binding Configurations');31}3233public function getSummaryText() {34return pht('This engine is used to edit Almanac bindings.');35}3637public function getEngineApplicationClass() {38return 'PhabricatorAlmanacApplication';39}4041protected function newEditableObject() {42$service = $this->getService();43return AlmanacBinding::initializeNewBinding($service);44}4546protected function newEditableObjectForDocumentation() {47$service_type = AlmanacCustomServiceType::SERVICETYPE;48$service = AlmanacService::initializeNewService($service_type);49$this->setService($service);50return $this->newEditableObject();51}5253protected function newEditableObjectFromConduit(array $raw_xactions) {54$service_phid = null;55foreach ($raw_xactions as $raw_xaction) {56if ($raw_xaction['type'] !== 'service') {57continue;58}5960$service_phid = $raw_xaction['value'];61}6263if ($service_phid === null) {64throw new Exception(65pht(66'When creating a new Almanac binding via the Conduit API, you '.67'must provide a "service" transaction to select a service to bind.'));68}6970$service = id(new AlmanacServiceQuery())71->setViewer($this->getViewer())72->withPHIDs(array($service_phid))73->requireCapabilities(74array(75PhabricatorPolicyCapability::CAN_VIEW,76PhabricatorPolicyCapability::CAN_EDIT,77))78->executeOne();79if (!$service) {80throw new Exception(81pht(82'Service "%s" is unrecognized, restricted, or you do not have '.83'permission to edit it.',84$service_phid));85}8687$this->setService($service);8889return $this->newEditableObject();90}9192protected function newObjectQuery() {93return id(new AlmanacBindingQuery())94->needProperties(true);95}9697protected function getObjectCreateTitleText($object) {98return pht('Create Binding');99}100101protected function getObjectCreateButtonText($object) {102return pht('Create Binding');103}104105protected function getObjectEditTitleText($object) {106return pht('Edit Binding');107}108109protected function getObjectEditShortText($object) {110return pht('Edit Binding');111}112113protected function getObjectCreateShortText() {114return pht('Create Binding');115}116117protected function getObjectName() {118return pht('Binding');119}120121protected function getEditorURI() {122return '/almanac/binding/edit/';123}124125protected function getObjectCreateCancelURI($object) {126return '/almanac/binding/';127}128129protected function getObjectViewURI($object) {130return $object->getURI();131}132133protected function buildCustomEditFields($object) {134return array(135id(new PhabricatorTextEditField())136->setKey('service')137->setLabel(pht('Service'))138->setIsFormField(false)139->setTransactionType(140AlmanacBindingServiceTransaction::TRANSACTIONTYPE)141->setDescription(pht('Service to create a binding for.'))142->setConduitDescription(pht('Select the service to bind.'))143->setConduitTypeDescription(pht('Service PHID.'))144->setValue($object->getServicePHID()),145id(new PhabricatorTextEditField())146->setKey('interface')147->setLabel(pht('Interface'))148->setIsFormField(false)149->setTransactionType(150AlmanacBindingInterfaceTransaction::TRANSACTIONTYPE)151->setDescription(pht('Interface to bind the service to.'))152->setConduitDescription(pht('Set the interface to bind.'))153->setConduitTypeDescription(pht('Interface PHID.'))154->setValue($object->getInterfacePHID()),155id(new PhabricatorBoolEditField())156->setKey('disabled')157->setLabel(pht('Disabled'))158->setIsFormField(false)159->setTransactionType(160AlmanacBindingDisableTransaction::TRANSACTIONTYPE)161->setDescription(pht('Disable or enable the binding.'))162->setConduitDescription(pht('Disable or enable the binding.'))163->setConduitTypeDescription(pht('True to disable the binding.'))164->setValue($object->getIsDisabled())165->setOptions(166pht('Enable Binding'),167pht('Disable Binding')),168);169}170171}172173174