1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-11 16:16:14 +01:00
phorge-phorge/src/applications/transactions/controller/PhabricatorEditEngineConfigurationDefaultsController.php
Austin McKinley 6b9f4a918b Modularize PhabricatorEditEngineConfigurationTransaction
Summary: Ref T13319. Ref PHI1302. Migrate `PhabricatorEditEngineConfigurationTransaction` to modular transactions and add some additional transaction rendering to make these edits less opaque.

Test Plan: Hit all the form edit controllers, viewed resulting transaction timeline.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T13319

Differential Revision: https://secure.phabricator.com/D20595
2019-06-20 16:25:21 -07:00

128 lines
3.4 KiB
PHP

<?php
final class PhabricatorEditEngineConfigurationDefaultsController
extends PhabricatorEditEngineController {
public function handleRequest(AphrontRequest $request) {
$engine_key = $request->getURIData('engineKey');
$this->setEngineKey($engine_key);
$key = $request->getURIData('key');
$viewer = $this->getViewer();
$config = id(new PhabricatorEditEngineConfigurationQuery())
->setViewer($viewer)
->withEngineKeys(array($engine_key))
->withIdentifiers(array($key))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$config) {
return id(new Aphront404Response());
}
$cancel_uri = "/transactions/editengine/{$engine_key}/view/{$key}/";
$engine = $config->getEngine();
$fields = $engine->getFieldsForConfig($config);
foreach ($fields as $key => $field) {
if (!$field->getIsFormField()) {
unset($fields[$key]);
continue;
}
if (!$field->getIsDefaultable()) {
unset($fields[$key]);
continue;
}
}
foreach ($fields as $field) {
$field->setIsEditDefaults(true);
}
if ($request->isFormPost()) {
$xactions = array();
foreach ($fields as $field) {
$field->readValueFromSubmit($request);
}
$type = PhabricatorEditEngineDefaultTransaction::TRANSACTIONTYPE;
$xactions = array();
foreach ($fields as $field) {
$new_value = $field->getValueForDefaults();
$xactions[] = id(new PhabricatorEditEngineConfigurationTransaction())
->setTransactionType($type)
->setMetadataValue('field.key', $field->getKey())
->setNewValue($new_value);
}
$editor = id(new PhabricatorEditEngineConfigurationEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true);
$editor->applyTransactions($config, $xactions);
return id(new AphrontRedirectResponse())
->setURI($cancel_uri);
}
$title = pht('Edit Form Defaults');
$form = id(new AphrontFormView())
->setUser($viewer);
foreach ($fields as $field) {
$field->appendToForm($form);
}
$form
->appendControl(
id(new AphrontFormSubmitControl())
->setValue(pht('Save Defaults'))
->addCancelButton($cancel_uri));
$info = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
->setErrors(
array(
pht('You are editing the default values for this form.'),
));
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Form'))
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setForm($form);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Form %d', $config->getID()), $cancel_uri);
$crumbs->addTextCrumb(pht('Edit Defaults'));
$crumbs->setBorder(true);
$header = id(new PHUIHeaderView())
->setHeader(pht('Edit Form Defaults'))
->setHeaderIcon('fa-pencil');
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setFooter(array(
$info,
$box,
));
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
}
}