Path: blob/master/src/applications/drydock/editor/DrydockBlueprintEditEngine.php
12256 views
<?php12final class DrydockBlueprintEditEngine3extends PhabricatorEditEngine {45private $blueprintImplementation;67const ENGINECONST = 'drydock.blueprint';89public function isEngineConfigurable() {10return false;11}1213public function getEngineName() {14return pht('Drydock Blueprints');15}1617public function getSummaryHeader() {18return pht('Edit Drydock Blueprint Configurations');19}2021public function getSummaryText() {22return pht('This engine is used to edit Drydock blueprints.');23}2425public function getEngineApplicationClass() {26return 'PhabricatorDrydockApplication';27}2829public function setBlueprintImplementation(30DrydockBlueprintImplementation $impl) {31$this->blueprintImplementation = $impl;32return $this;33}3435public function getBlueprintImplementation() {36return $this->blueprintImplementation;37}3839protected function newEditableObject() {40$viewer = $this->getViewer();41$blueprint = DrydockBlueprint::initializeNewBlueprint($viewer);4243$impl = $this->getBlueprintImplementation();44if ($impl) {45$blueprint46->setClassName(get_class($impl))47->attachImplementation(clone $impl);48}4950return $blueprint;51}5253protected function newEditableObjectFromConduit(array $raw_xactions) {54$type = null;55foreach ($raw_xactions as $raw_xaction) {56if ($raw_xaction['type'] !== 'type') {57continue;58}5960$type = $raw_xaction['value'];61}6263if ($type === null) {64throw new Exception(65pht(66'When creating a new Drydock blueprint via the Conduit API, you '.67'must provide a "type" transaction to select a type.'));68}6970$map = DrydockBlueprintImplementation::getAllBlueprintImplementations();71if (!isset($map[$type])) {72throw new Exception(73pht(74'Blueprint type "%s" is unrecognized. Valid types are: %s.',75$type,76implode(', ', array_keys($map))));77}7879$impl = clone $map[$type];80$this->setBlueprintImplementation($impl);8182return $this->newEditableObject();83}8485protected function newEditableObjectForDocumentation() {86// In order to generate the proper list of fields/transactions for a87// blueprint, a blueprint's type needs to be known upfront, and there's88// currently no way to pre-specify the type. Hardcoding an implementation89// here prevents the fatal on the Conduit API page and allows transactions90// to be edited.91$impl = new DrydockWorkingCopyBlueprintImplementation();92$this->setBlueprintImplementation($impl);93return $this->newEditableObject();94}9596protected function newObjectQuery() {97return new DrydockBlueprintQuery();98}99100protected function getObjectCreateTitleText($object) {101return pht('Create Blueprint');102}103104protected function getObjectCreateButtonText($object) {105return pht('Create Blueprint');106}107108protected function getObjectEditTitleText($object) {109return pht('Edit Blueprint: %s', $object->getBlueprintName());110}111112protected function getObjectEditShortText($object) {113return pht('Edit Blueprint');114}115116protected function getObjectCreateShortText() {117return pht('Create Blueprint');118}119120protected function getObjectName() {121return pht('Blueprint');122}123124protected function getEditorURI() {125return '/drydock/blueprint/edit/';126}127128protected function getObjectCreateCancelURI($object) {129return '/drydock/blueprint/';130}131132protected function getObjectViewURI($object) {133$id = $object->getID();134return "/drydock/blueprint/{$id}/";135}136137protected function getCreateNewObjectPolicy() {138return $this->getApplication()->getPolicy(139DrydockCreateBlueprintsCapability::CAPABILITY);140}141142protected function buildCustomEditFields($object) {143$impl = $object->getImplementation();144145return array(146// This field appears in the web UI147id(new PhabricatorStaticEditField())148->setKey('displayType')149->setLabel(pht('Blueprint Type'))150->setDescription(pht('Type of blueprint.'))151->setValue($impl->getBlueprintName()),152id(new PhabricatorTextEditField())153->setKey('type')154->setLabel(pht('Type'))155->setIsFormField(false)156->setTransactionType(157DrydockBlueprintTypeTransaction::TRANSACTIONTYPE)158->setDescription(pht('When creating a blueprint, set the type.'))159->setConduitDescription(pht('Set the blueprint type.'))160->setConduitTypeDescription(pht('Blueprint type.'))161->setValue($object->getClassName()),162id(new PhabricatorTextEditField())163->setKey('name')164->setLabel(pht('Name'))165->setDescription(pht('Name of the blueprint.'))166->setTransactionType(DrydockBlueprintNameTransaction::TRANSACTIONTYPE)167->setIsRequired(true)168->setValue($object->getBlueprintName()),169);170}171172}173174175