diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a6a05f9ede..acb883cb1f 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -569,7 +569,9 @@ phutil_register_library_map(array( 'DrydockApacheWebrootInterface' => 'applications/drydock/interface/webroot/DrydockApacheWebrootInterface.php', 'DrydockBlueprint' => 'applications/drydock/storage/DrydockBlueprint.php', 'DrydockBlueprintController' => 'applications/drydock/controller/DrydockBlueprintController.php', + 'DrydockBlueprintCoreCustomField' => 'applications/drydock/customfield/DrydockBlueprintCoreCustomField.php', 'DrydockBlueprintCreateController' => 'applications/drydock/controller/DrydockBlueprintCreateController.php', + 'DrydockBlueprintCustomField' => 'applications/drydock/customfield/DrydockBlueprintCustomField.php', 'DrydockBlueprintEditController' => 'applications/drydock/controller/DrydockBlueprintEditController.php', 'DrydockBlueprintEditor' => 'applications/drydock/editor/DrydockBlueprintEditor.php', 'DrydockBlueprintImplementation' => 'applications/drydock/blueprint/DrydockBlueprintImplementation.php', @@ -3306,9 +3308,15 @@ phutil_register_library_map(array( 'DrydockBlueprint' => array( 'DrydockDAO', 'PhabricatorPolicyInterface', + 'PhabricatorCustomFieldInterface', ), 'DrydockBlueprintController' => 'DrydockController', + 'DrydockBlueprintCoreCustomField' => array( + 'DrydockBlueprintCustomField', + 'PhabricatorStandardCustomFieldInterface', + ), 'DrydockBlueprintCreateController' => 'DrydockBlueprintController', + 'DrydockBlueprintCustomField' => 'PhabricatorCustomField', 'DrydockBlueprintEditController' => 'DrydockBlueprintController', 'DrydockBlueprintEditor' => 'PhabricatorApplicationTransactionEditor', 'DrydockBlueprintListController' => 'DrydockBlueprintController', diff --git a/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php index 34373aaf11..18ca597a90 100644 --- a/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php +++ b/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php @@ -56,6 +56,14 @@ abstract class DrydockBlueprintImplementation { return $this; } + public function getFieldSpecifications() { + return array(); + } + + public function getDetail($key, $default = null) { + return $this->getInstance()->getDetail($key, $default); + } + /* -( Lease Acquisition )-------------------------------------------------- */ diff --git a/src/applications/drydock/controller/DrydockBlueprintEditController.php b/src/applications/drydock/controller/DrydockBlueprintEditController.php index bd61795767..4211c80b4c 100644 --- a/src/applications/drydock/controller/DrydockBlueprintEditController.php +++ b/src/applications/drydock/controller/DrydockBlueprintEditController.php @@ -44,9 +44,17 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController { $cancel_uri = $this->getApplicationURI('blueprint/'); } + $field_list = PhabricatorCustomField::getObjectFields( + $blueprint, + PhabricatorCustomField::ROLE_EDIT); + $field_list + ->setViewer($viewer) + ->readFieldsFromStorage($blueprint); + $v_name = $blueprint->getBlueprintName(); $e_name = true; $errors = array(); + $validation_exception = null; if ($request->isFormPost()) { $v_view_policy = $request->getStr('viewPolicy'); @@ -60,6 +68,10 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController { if (!$errors) { $xactions = array(); + $xactions = $field_list->buildFieldTransactionsFromRequest( + new DrydockBlueprintTransaction(), + $request); + $xactions[] = id(new DrydockBlueprintTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) ->setNewValue($v_view_policy); @@ -77,12 +89,16 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController { ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true); - $editor->applyTransactions($blueprint, $xactions); + try { + $editor->applyTransactions($blueprint, $xactions); - $id = $blueprint->getID(); - $save_uri = $this->getApplicationURI("blueprint/{$id}/"); + $id = $blueprint->getID(); + $save_uri = $this->getApplicationURI("blueprint/{$id}/"); - return id(new AphrontRedirectResponse())->setURI($save_uri); + return id(new AphrontRedirectResponse())->setURI($save_uri); + } catch (PhabricatorApplicationTransactionValidationException $ex) { + $validation_exception = $ex; + } } } @@ -117,6 +133,8 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController { ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) ->setPolicies($policies)); + $field_list->appendFieldsToForm($form); + $crumbs = $this->buildApplicationCrumbs(); if ($blueprint->getID()) { @@ -139,6 +157,7 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController { $box = id(new PHUIObjectBoxView()) ->setHeaderText($header) + ->setValidationException($validation_exception) ->setFormErrors($errors) ->setForm($form); diff --git a/src/applications/drydock/controller/DrydockBlueprintViewController.php b/src/applications/drydock/controller/DrydockBlueprintViewController.php index 7e07f092ec..9f82dc967a 100644 --- a/src/applications/drydock/controller/DrydockBlueprintViewController.php +++ b/src/applications/drydock/controller/DrydockBlueprintViewController.php @@ -61,6 +61,18 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController { ->withObjectPHIDs(array($blueprint->getPHID())) ->execute(); + $field_list = PhabricatorCustomField::getObjectFields( + $blueprint, + PhabricatorCustomField::ROLE_VIEW); + $field_list + ->setViewer($viewer) + ->readFieldsFromStorage($blueprint); + + $field_list->appendFieldsToPropertyList( + $blueprint, + $viewer, + $properties); + $engine = id(new PhabricatorMarkupEngine()) ->setViewer($viewer); diff --git a/src/applications/drydock/customfield/DrydockBlueprintCoreCustomField.php b/src/applications/drydock/customfield/DrydockBlueprintCoreCustomField.php new file mode 100644 index 0000000000..3f4a2acc67 --- /dev/null +++ b/src/applications/drydock/customfield/DrydockBlueprintCoreCustomField.php @@ -0,0 +1,43 @@ +getImplementation(); + $specs = $impl->getFieldSpecifications(); + + return PhabricatorStandardCustomField::buildStandardFields($this, $specs); + } + + public function shouldUseStorage() { + return false; + } + + public function readValueFromObject(PhabricatorCustomFieldInterface $object) { + $key = $this->getProxy()->getRawStandardFieldKey(); + $this->setValueFromStorage($object->getDetail($key)); + } + + public function applyApplicationTransactionInternalEffects( + PhabricatorApplicationTransaction $xaction) { + $object = $this->getObject(); + $key = $this->getProxy()->getRawStandardFieldKey(); + + $this->setValueFromApplicationTransactions($xaction->getNewValue()); + $value = $this->getValueForStorage(); + + $object->setDetail($key, $value); + } + + public function applyApplicationTransactionExternalEffects( + PhabricatorApplicationTransaction $xaction) { + return; + } + +} diff --git a/src/applications/drydock/customfield/DrydockBlueprintCustomField.php b/src/applications/drydock/customfield/DrydockBlueprintCustomField.php new file mode 100644 index 0000000000..1d37a19209 --- /dev/null +++ b/src/applications/drydock/customfield/DrydockBlueprintCustomField.php @@ -0,0 +1,6 @@ +details, $key, $default); + } + + public function setDetail($key, $value) { + $this->details[$key] = $value; + return $this; + } + /* -( PhabricatorPolicyInterface )----------------------------------------- */ @@ -86,4 +98,27 @@ final class DrydockBlueprint extends DrydockDAO return null; } + +/* -( PhabricatorCustomFieldInterface )------------------------------------ */ + + + public function getCustomFieldSpecificationForRole($role) { + return array(); + } + + public function getCustomFieldBaseClass() { + return 'DrydockBlueprintCustomField'; + } + + public function getCustomFields() { + return $this->assertAttached($this->customFields); + } + + public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) { + $this->customFields = $fields; + return $this; + } + + + }