Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngine.php
| Show All 40 Lines | abstract class PhabricatorEditEngine | ||||
| final public function getController() { | final public function getController() { | ||||
| return $this->controller; | return $this->controller; | ||||
| } | } | ||||
| final public function getEngineKey() { | final public function getEngineKey() { | ||||
| return $this->getPhobjectClassConstant('ENGINECONST', 64); | return $this->getPhobjectClassConstant('ENGINECONST', 64); | ||||
| } | } | ||||
| final public function getApplication() { | |||||
| $app_class = $this->getEngineApplicationClass(); | |||||
| return PhabricatorApplication::getByClass($app_class); | |||||
| } | |||||
| /* -( Managing Fields )---------------------------------------------------- */ | /* -( Managing Fields )---------------------------------------------------- */ | ||||
| abstract public function getEngineApplicationClass(); | abstract public function getEngineApplicationClass(); | ||||
| abstract protected function buildCustomEditFields($object); | abstract protected function buildCustomEditFields($object); | ||||
| public function getFieldsForConfig( | |||||
| PhabricatorEditEngineConfiguration $config) { | |||||
| $object = $this->newEditableObject(); | |||||
| $this->editEngineConfiguration = $config; | |||||
| return $this->buildEditFields($object); | |||||
| } | |||||
| final protected function buildEditFields($object) { | final protected function buildEditFields($object) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $editor = $object->getApplicationTransactionEditor(); | $editor = $object->getApplicationTransactionEditor(); | ||||
| $types = $editor->getTransactionTypesForObject($object); | $types = $editor->getTransactionTypesForObject($object); | ||||
| $types = array_fuse($types); | $types = array_fuse($types); | ||||
| $fields = $this->buildCustomEditFields($object); | $fields = $this->buildCustomEditFields($object); | ||||
| ▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | if ($object instanceof PhabricatorPolicyInterface) { | ||||
| $type_space = PhabricatorTransactions::TYPE_SPACE; | $type_space = PhabricatorTransactions::TYPE_SPACE; | ||||
| if (isset($types[$type_space])) { | if (isset($types[$type_space])) { | ||||
| $space_field = id(new PhabricatorSpaceEditField()) | $space_field = id(new PhabricatorSpaceEditField()) | ||||
| ->setKey('spacePHID') | ->setKey('spacePHID') | ||||
| ->setLabel(pht('Space')) | ->setLabel(pht('Space')) | ||||
| ->setEditTypeKey('space') | ->setEditTypeKey('space') | ||||
| ->setDescription( | ->setDescription( | ||||
| pht('Shifts the object in the Spaces application.')) | pht('Shifts the object in the Spaces application.')) | ||||
| ->setIsReorderable(false) | |||||
| ->setAliases(array('space', 'policy.space')) | ->setAliases(array('space', 'policy.space')) | ||||
| ->setTransactionType($type_space) | ->setTransactionType($type_space) | ||||
| ->setValue($object->getSpacePHID()); | ->setValue($object->getSpacePHID()); | ||||
| $fields[] = $space_field; | $fields[] = $space_field; | ||||
| $policy_field->setSpaceField($space_field); | $policy_field->setSpaceField($space_field); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | /* -( Display Text )------------------------------------------------------- */ | ||||
| abstract public function getEngineName(); | abstract public function getEngineName(); | ||||
| /** | /** | ||||
| * @task text | * @task text | ||||
| */ | */ | ||||
| abstract protected function getObjectCreateTitleText($object); | abstract protected function getObjectCreateTitleText($object); | ||||
| /** | |||||
| * @task text | |||||
| */ | |||||
| protected function getFormHeaderText($object) { | |||||
| $config = $this->getEditEngineConfiguration(); | |||||
| return $config->getName(); | |||||
| } | |||||
| /** | /** | ||||
| * @task text | * @task text | ||||
| */ | */ | ||||
| abstract protected function getObjectEditTitleText($object); | abstract protected function getObjectEditTitleText($object); | ||||
| /** | /** | ||||
| ▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | /* -( Managing URIs )------------------------------------------------------ */ | ||||
| * @task uri | * @task uri | ||||
| */ | */ | ||||
| abstract protected function getObjectViewURI($object); | abstract protected function getObjectViewURI($object); | ||||
| /** | /** | ||||
| * @task uri | * @task uri | ||||
| */ | */ | ||||
| protected function getObjectEditURI($object) { | protected function getObjectCreateCancelURI($object) { | ||||
| return $this->getController()->getApplicationURI('edit/'); | return $this->getApplication()->getApplicationURI(); | ||||
| } | } | ||||
| /** | /** | ||||
| * @task uri | * @task uri | ||||
| */ | */ | ||||
| protected function getObjectCreateCancelURI($object) { | protected function getEditorURI() { | ||||
| return $this->getController()->getApplicationURI(); | return $this->getApplication()->getApplicationURI('edit/'); | ||||
| } | } | ||||
| /** | /** | ||||
| * @task uri | * @task uri | ||||
| */ | */ | ||||
| protected function getObjectEditCancelURI($object) { | protected function getObjectEditCancelURI($object) { | ||||
| return $this->getObjectViewURI($object); | return $this->getObjectViewURI($object); | ||||
| } | } | ||||
| /** | /** | ||||
| * @task uri | * @task uri | ||||
| */ | */ | ||||
| protected function getEditURI($object, $path = null) { | public function getEditURI($object = null, $path = null) { | ||||
| $parts = array( | $parts = array(); | ||||
| $this->getObjectEditURI($object), | |||||
| ); | $parts[] = $this->getEditorURI(); | ||||
| if (!$this->getIsCreate()) { | if ($object && $object->getID()) { | ||||
| $parts[] = $object->getID().'/'; | $parts[] = $object->getID().'/'; | ||||
| } | } | ||||
| if ($path !== null) { | if ($path !== null) { | ||||
| $parts[] = $path; | $parts[] = $path; | ||||
| } | } | ||||
| return implode('', $parts); | return implode('', $parts); | ||||
| ▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | |||||
| /* -( Responding to Web Requests )----------------------------------------- */ | /* -( Responding to Web Requests )----------------------------------------- */ | ||||
| final public function buildResponse() { | final public function buildResponse() { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $controller = $this->getController(); | $controller = $this->getController(); | ||||
| $request = $controller->getRequest(); | $request = $controller->getRequest(); | ||||
| $config = $this->loadEditEngineConfiguration($request->getURIData('form')); | $form_key = $request->getURIData('formKey'); | ||||
| $config = $this->loadEditEngineConfiguration($form_key); | |||||
| if (!$config) { | if (!$config) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| $id = $request->getURIData('id'); | $id = $request->getURIData('id'); | ||||
| if ($id) { | if ($id) { | ||||
| $this->setIsCreate(false); | $this->setIsCreate(false); | ||||
| $object = $this->newObjectFromID($id); | $object = $this->newObjectFromID($id); | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | if ($request->isFormPost()) { | ||||
| $field->readValueFromObject($object); | $field->readValueFromObject($object); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| $action_button = $this->buildEditFormActionButton($object); | $action_button = $this->buildEditFormActionButton($object); | ||||
| if ($this->getIsCreate()) { | if ($this->getIsCreate()) { | ||||
| $header_text = $this->getObjectCreateTitleText($object); | $header_text = $this->getFormHeaderText($object); | ||||
| } else { | } else { | ||||
| $header_text = $this->getObjectEditTitleText($object); | $header_text = $this->getObjectEditTitleText($object); | ||||
| } | } | ||||
| $header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
| ->setHeader($header_text) | ->setHeader($header_text) | ||||
| ->addActionLink($action_button); | ->addActionLink($action_button); | ||||
| ▲ Show 20 Lines • Show All 338 Lines • Show Last 20 Lines | |||||