Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/editor/AlmanacInterfaceEditEngine.php
| Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | protected function newEditableObject() { | ||||
| $device = $this->getDevice(); | $device = $this->getDevice(); | ||||
| $interface | $interface | ||||
| ->setDevicePHID($device->getPHID()) | ->setDevicePHID($device->getPHID()) | ||||
| ->attachDevice($device); | ->attachDevice($device); | ||||
| return $interface; | return $interface; | ||||
| } | } | ||||
| protected function newEditableObjectForDocumentation() { | |||||
| $this->setDevice(new AlmanacDevice()); | |||||
| return $this->newEditableObject(); | |||||
| } | |||||
| protected function newEditableObjectFromConduit(array $raw_xactions) { | |||||
| $device_phid = null; | |||||
| foreach ($raw_xactions as $raw_xaction) { | |||||
| if ($raw_xaction['type'] !== 'device') { | |||||
| continue; | |||||
| } | |||||
| $device_phid = $raw_xaction['value']; | |||||
| } | |||||
| if ($device_phid === null) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'When creating a new Almanac interface via the Conduit API, you '. | |||||
| 'must provide a "device" transaction to select a device.')); | |||||
| } | |||||
| $device = id(new AlmanacDeviceQuery()) | |||||
| ->setViewer($this->getViewer()) | |||||
| ->withPHIDs(array($device_phid)) | |||||
| ->requireCapabilities( | |||||
| array( | |||||
| PhabricatorPolicyCapability::CAN_VIEW, | |||||
| PhabricatorPolicyCapability::CAN_EDIT, | |||||
| )) | |||||
| ->executeOne(); | |||||
| if (!$device) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Device "%s" is unrecognized, restricted, or you do not have '. | |||||
| 'permission to edit it.', | |||||
| $device_phid)); | |||||
| } | |||||
| $this->setDevice($device); | |||||
| return $this->newEditableObject(); | |||||
| } | |||||
| protected function newObjectQuery() { | protected function newObjectQuery() { | ||||
| return new AlmanacInterfaceQuery(); | return new AlmanacInterfaceQuery(); | ||||
| } | } | ||||
| protected function getObjectCreateTitleText($object) { | protected function getObjectCreateTitleText($object) { | ||||
| return pht('Create Interface'); | return pht('Create Interface'); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | return array( | ||||
| id(new PhabricatorTextEditField()) | id(new PhabricatorTextEditField()) | ||||
| ->setKey('address') | ->setKey('address') | ||||
| ->setLabel(pht('Address')) | ->setLabel(pht('Address')) | ||||
| ->setDescription(pht('Address of the service.')) | ->setDescription(pht('Address of the service.')) | ||||
| ->setTransactionType( | ->setTransactionType( | ||||
| AlmanacInterfaceAddressTransaction::TRANSACTIONTYPE) | AlmanacInterfaceAddressTransaction::TRANSACTIONTYPE) | ||||
| ->setIsRequired(true) | ->setIsRequired(true) | ||||
| ->setValue($object->getAddress()), | ->setValue($object->getAddress()), | ||||
| id(new PhabricatorTextEditField()) | id(new PhabricatorIntEditField()) | ||||
| ->setKey('port') | ->setKey('port') | ||||
| ->setLabel(pht('Port')) | ->setLabel(pht('Port')) | ||||
| ->setDescription(pht('Port of the service.')) | ->setDescription(pht('Port of the service.')) | ||||
| ->setTransactionType(AlmanacInterfacePortTransaction::TRANSACTIONTYPE) | ->setTransactionType(AlmanacInterfacePortTransaction::TRANSACTIONTYPE) | ||||
| ->setIsRequired(true) | ->setIsRequired(true) | ||||
| ->setValue($object->getPort()), | ->setValue($object->getPort()), | ||||
| ); | ); | ||||
| } | } | ||||
| } | } | ||||