Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngine.php
Show All 17 Lines | abstract class PhabricatorEditEngine | ||||
const EDITENGINECONFIG_DEFAULT = 'default'; | const EDITENGINECONFIG_DEFAULT = 'default'; | ||||
private $viewer; | private $viewer; | ||||
private $controller; | private $controller; | ||||
private $isCreate; | private $isCreate; | ||||
private $editEngineConfiguration; | private $editEngineConfiguration; | ||||
private $contextParameters = array(); | private $contextParameters = array(); | ||||
private $targetObject; | |||||
final public function setViewer(PhabricatorUser $viewer) { | final public function setViewer(PhabricatorUser $viewer) { | ||||
$this->viewer = $viewer; | $this->viewer = $viewer; | ||||
return $this; | return $this; | ||||
} | } | ||||
final public function getViewer() { | final public function getViewer() { | ||||
return $this->viewer; | return $this->viewer; | ||||
Show All 22 Lines | final public function addContextParameter($key) { | ||||
$this->contextParameters[] = $key; | $this->contextParameters[] = $key; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function isEngineConfigurable() { | public function isEngineConfigurable() { | ||||
return true; | return true; | ||||
} | } | ||||
public function isEngineExtensible() { | |||||
return true; | |||||
} | |||||
/** | |||||
* Force the engine to edit a particular object. | |||||
*/ | |||||
public function setTargetObject($target_object) { | |||||
$this->targetObject = $target_object; | |||||
return $this; | |||||
} | |||||
public function getTargetObject() { | |||||
return $this->targetObject; | |||||
} | |||||
/* -( 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( | public function getFieldsForConfig( | ||||
Show All 17 Lines | final protected function buildEditFields($object) { | ||||
foreach ($fields as $field) { | foreach ($fields as $field) { | ||||
$field | $field | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->setObject($object); | ->setObject($object); | ||||
} | } | ||||
$fields = mpull($fields, null, 'getKey'); | $fields = mpull($fields, null, 'getKey'); | ||||
if ($this->isEngineExtensible()) { | |||||
$extensions = PhabricatorEditEngineExtension::getAllEnabledExtensions(); | $extensions = PhabricatorEditEngineExtension::getAllEnabledExtensions(); | ||||
} else { | |||||
$extensions = array(); | |||||
} | |||||
foreach ($extensions as $extension) { | foreach ($extensions as $extension) { | ||||
$extension->setViewer($viewer); | $extension->setViewer($viewer); | ||||
if (!$extension->supportsObject($this, $object)) { | if (!$extension->supportsObject($this, $object)) { | ||||
continue; | continue; | ||||
} | } | ||||
$extension_fields = $extension->buildCustomEditFields($this, $object); | $extension_fields = $extension->buildCustomEditFields($this, $object); | ||||
▲ Show 20 Lines • Show All 609 Lines • ▼ Show 20 Lines | switch ($action) { | ||||
case 'nocreate': | case 'nocreate': | ||||
case 'nomanage': | case 'nomanage': | ||||
$require_create = false; | $require_create = false; | ||||
break; | break; | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
$object = $this->getTargetObject(); | |||||
if (!$object) { | |||||
$id = $request->getURIData('id'); | $id = $request->getURIData('id'); | ||||
if ($id) { | if ($id) { | ||||
$this->setIsCreate(false); | $this->setIsCreate(false); | ||||
$object = $this->newObjectFromID($id, $capabilities); | $object = $this->newObjectFromID($id, $capabilities); | ||||
if (!$object) { | if (!$object) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
} else { | } else { | ||||
// Make sure the viewer has permission to create new objects of | // Make sure the viewer has permission to create new objects of | ||||
// this type if we're going to create a new object. | // this type if we're going to create a new object. | ||||
if ($require_create) { | if ($require_create) { | ||||
$this->requireCreateCapability(); | $this->requireCreateCapability(); | ||||
} | } | ||||
$this->setIsCreate(true); | $this->setIsCreate(true); | ||||
$object = $this->newEditableObject(); | $object = $this->newEditableObject(); | ||||
} | } | ||||
} else { | |||||
$id = $object->getID(); | |||||
} | |||||
$this->validateObject($object); | $this->validateObject($object); | ||||
if ($use_default) { | if ($use_default) { | ||||
$config = $this->loadDefaultConfiguration(); | $config = $this->loadDefaultConfiguration(); | ||||
if (!$config) { | if (!$config) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | private function buildEditResponse($object) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$controller = $this->getController(); | $controller = $this->getController(); | ||||
$request = $controller->getRequest(); | $request = $controller->getRequest(); | ||||
$fields = $this->buildEditFields($object); | $fields = $this->buildEditFields($object); | ||||
$template = $object->getApplicationTransactionTemplate(); | $template = $object->getApplicationTransactionTemplate(); | ||||
$validation_exception = null; | $validation_exception = null; | ||||
if ($request->isFormPost()) { | if ($request->isFormPost() && $request->getBool('editEngine')) { | ||||
$submit_fields = $fields; | $submit_fields = $fields; | ||||
foreach ($submit_fields as $key => $field) { | foreach ($submit_fields as $key => $field) { | ||||
if (!$field->shouldGenerateTransactionsFromSubmit()) { | if (!$field->shouldGenerateTransactionsFromSubmit()) { | ||||
unset($submit_fields[$key]); | unset($submit_fields[$key]); | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | /* -( Responding to Web Requests )----------------------------------------- */ | ||||
} | } | ||||
private function buildEditForm($object, array $fields) { | private function buildEditForm($object, array $fields) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$controller = $this->getController(); | $controller = $this->getController(); | ||||
$request = $controller->getRequest(); | $request = $controller->getRequest(); | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($viewer); | ->setUser($viewer) | ||||
->addHiddenInput('editEngine', 'true'); | |||||
foreach ($this->contextParameters as $param) { | foreach ($this->contextParameters as $param) { | ||||
$form->addHiddenInput($param, $request->getStr($param)); | $form->addHiddenInput($param, $request->getStr($param)); | ||||
} | } | ||||
foreach ($fields as $field) { | foreach ($fields as $field) { | ||||
$field->appendToForm($form); | $field->appendToForm($form); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 832 Lines • Show Last 20 Lines |