Path: blob/master/src/applications/almanac/editor/AlmanacDeviceEditEngine.php
12256 views
<?php12final class AlmanacDeviceEditEngine3extends PhabricatorEditEngine {45const ENGINECONST = 'almanac.device';67public function isEngineConfigurable() {8return false;9}1011public function getEngineName() {12return pht('Almanac Devices');13}1415public function getSummaryHeader() {16return pht('Edit Almanac Device Configurations');17}1819public function getSummaryText() {20return pht('This engine is used to edit Almanac devices.');21}2223public function getEngineApplicationClass() {24return 'PhabricatorAlmanacApplication';25}2627protected function newEditableObject() {28return AlmanacDevice::initializeNewDevice();29}3031protected function newObjectQuery() {32return id(new AlmanacDeviceQuery())33->needProperties(true);34}3536protected function getObjectCreateTitleText($object) {37return pht('Create Device');38}3940protected function getObjectCreateButtonText($object) {41return pht('Create Device');42}4344protected function getObjectEditTitleText($object) {45return pht('Edit Device: %s', $object->getName());46}4748protected function getObjectEditShortText($object) {49return pht('Edit Device');50}5152protected function getObjectCreateShortText() {53return pht('Create Device');54}5556protected function getObjectName() {57return pht('Device');58}5960protected function getEditorURI() {61return '/almanac/device/edit/';62}6364protected function getObjectCreateCancelURI($object) {65return '/almanac/device/';66}6768protected function getObjectViewURI($object) {69return $object->getURI();70}7172protected function getCreateNewObjectPolicy() {73return $this->getApplication()->getPolicy(74AlmanacCreateDevicesCapability::CAPABILITY);75}7677protected function buildCustomEditFields($object) {78$status_map = $this->getDeviceStatusMap($object);7980return array(81id(new PhabricatorTextEditField())82->setKey('name')83->setLabel(pht('Name'))84->setDescription(pht('Name of the device.'))85->setTransactionType(AlmanacDeviceNameTransaction::TRANSACTIONTYPE)86->setIsRequired(true)87->setValue($object->getName()),88id(new PhabricatorSelectEditField())89->setKey('status')90->setLabel(pht('Status'))91->setDescription(pht('Device status.'))92->setTransactionType(AlmanacDeviceStatusTransaction::TRANSACTIONTYPE)93->setOptions($status_map)94->setValue($object->getStatus()),95);96}979899private function getDeviceStatusMap(AlmanacDevice $device) {100$status_map = AlmanacDeviceStatus::getStatusMap();101102// If the device currently has an unknown status, add it to the list for103// the dropdown.104$status_value = $device->getStatus();105if (!isset($status_map[$status_value])) {106$status_map = array(107$status_value => AlmanacDeviceStatus::newStatusFromValue($status_value),108) + $status_map;109}110111$status_map = mpull($status_map, 'getName');112113return $status_map;114}115116}117118119