2015-11-18 19:38:12 +01:00
|
|
|
<?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) {
|
Allow "Change Subtype" to be selected from the comment action stack
Summary:
Ref T13222. See PHI683. Currently, you can "Change subtype..." via Conduit and the bulk editor, but not via the comment action stack or edit forms.
In PHI683 an install is doing this often enough that they'd like it to become a first-class action. I've generally been cautious about pushing this action to become a first-class action (there are some inevitable rough edges and I don't want to add too much complexity if there isn't a use case for it) but since we have evidence that users would find it useful and nothing has exploded yet, I'm comfortable taking another step forward.
Currently, `EditEngine` has this sort of weird `setIsConduitOnly()` method. This actually means more like "this doesn't show up on forms". Make it better align with that. In particular, a "conduit only" field can already show up in the bulk editor, which is goofy. Change this to `setIsFormField()` and convert/simplify existing callsites.
Test Plan:
There are a lot of ways to reach EditEngine so this probably isn't entirely exhaustive, but I think I got pretty much anything which is likely to break:
- Searched for `setIsConduitOnly()` and `getIsConduitOnly()`, converted all callsites to `setIsFormField()`.
- Searched for `setIsLockable()`, `setIsReorderable()` and `setIsDefaultable()` and aligned these calls to intent where applicable.
- Created an Almanac binding.
- Edited an Almanac binding.
- Created an Almanac service.
- Edited an Almanac service.
- Edited a binding property.
- Deleted a binding property.
- Created and edited a badge.
- Awarded and revoked a badge.
- Created and edited an event.
- Made an event recurring.
- Created and edited a Conpherence thread.
- Edited and updated the diff for a revision.
- Created and edited a repository.
- Created and disabled repository URIs.
- Created and edited a blueprint.
- Created and edited tasks.
- Created a paste, edited/archived a paste.
- Created/edited/archived a package.
- Created/edited a project.
- Made comments.
- Moved tasks on workboards via comment action stack.
- Changed task subtype via comment action stack.
Reviewers: amckinley
Reviewed By: amckinley
Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam
Maniphest Tasks: T13222
Differential Revision: https://secure.phabricator.com/D19842
2018-11-27 00:44:48 +01:00
|
|
|
if (!$field->getIsFormField()) {
|
|
|
|
unset($fields[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-11-18 19:38:12 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-06-20 00:16:16 +02:00
|
|
|
$type = PhabricatorEditEngineDefaultTransaction::TRANSACTIONTYPE;
|
2015-11-18 19:38:12 +01:00
|
|
|
|
|
|
|
$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())
|
2016-03-28 18:05:22 +02:00
|
|
|
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
|
2015-11-18 19:38:12 +01:00
|
|
|
->setErrors(
|
|
|
|
array(
|
|
|
|
pht('You are editing the default values for this form.'),
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
2016-03-28 18:05:22 +02:00
|
|
|
->setHeaderText(pht('Form'))
|
|
|
|
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
2015-11-18 19:38:12 +01:00
|
|
|
->setForm($form);
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addTextCrumb(pht('Form %d', $config->getID()), $cancel_uri);
|
|
|
|
$crumbs->addTextCrumb(pht('Edit Defaults'));
|
2016-03-28 18:05:22 +02:00
|
|
|
$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,
|
|
|
|
));
|
2015-11-18 19:38:12 +01:00
|
|
|
|
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title)
|
|
|
|
->setCrumbs($crumbs)
|
2016-03-28 18:05:22 +02:00
|
|
|
->appendChild($view);
|
2015-11-18 19:38:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|