Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/editor/AlmanacDeviceEditEngine.php
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | final class AlmanacDeviceEditEngine | ||||
} | } | ||||
protected function getCreateNewObjectPolicy() { | protected function getCreateNewObjectPolicy() { | ||||
return $this->getApplication()->getPolicy( | return $this->getApplication()->getPolicy( | ||||
AlmanacCreateDevicesCapability::CAPABILITY); | AlmanacCreateDevicesCapability::CAPABILITY); | ||||
} | } | ||||
protected function buildCustomEditFields($object) { | protected function buildCustomEditFields($object) { | ||||
$status_map = $this->getDeviceStatusMap($object); | |||||
return array( | return array( | ||||
id(new PhabricatorTextEditField()) | id(new PhabricatorTextEditField()) | ||||
->setKey('name') | ->setKey('name') | ||||
->setLabel(pht('Name')) | ->setLabel(pht('Name')) | ||||
->setDescription(pht('Name of the device.')) | ->setDescription(pht('Name of the device.')) | ||||
->setTransactionType(AlmanacDeviceNameTransaction::TRANSACTIONTYPE) | ->setTransactionType(AlmanacDeviceNameTransaction::TRANSACTIONTYPE) | ||||
->setIsRequired(true) | ->setIsRequired(true) | ||||
->setValue($object->getName()), | ->setValue($object->getName()), | ||||
id(new PhabricatorSelectEditField()) | |||||
->setKey('status') | |||||
->setLabel(pht('Status')) | |||||
->setDescription(pht('Device status.')) | |||||
->setTransactionType(AlmanacDeviceStatusTransaction::TRANSACTIONTYPE) | |||||
->setOptions($status_map) | |||||
->setValue($object->getStatus()), | |||||
); | ); | ||||
} | } | ||||
private function getDeviceStatusMap(AlmanacDevice $device) { | |||||
$status_map = AlmanacDeviceStatus::getStatusMap(); | |||||
// If the device currently has an unknown status, add it to the list for | |||||
// the dropdown. | |||||
$status_value = $device->getStatus(); | |||||
if (!isset($status_map[$status_value])) { | |||||
$status_map = array( | |||||
$status_value => AlmanacDeviceStatus::newStatusFromValue($status_value), | |||||
) + $status_map; | |||||
} | |||||
$status_map = mpull($status_map, 'getName'); | |||||
return $status_map; | |||||
} | |||||
} | } |