Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / almanac / controller / AlmanacPropertyEditController.php
blobef587e5b05b28003e81763eb1d942e43fe0f0b4f
1 <?php
3 final class AlmanacPropertyEditController
4 extends AlmanacPropertyController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
9 $response = $this->loadPropertyObject();
10 if ($response) {
11 return $response;
14 $object = $this->getPropertyObject();
16 $cancel_uri = $object->getURI();
17 $property_key = $request->getStr('key');
19 if (!strlen($property_key)) {
20 return $this->buildPropertyKeyResponse($cancel_uri, null);
21 } else {
22 $error = null;
23 try {
24 AlmanacNames::validateName($property_key);
25 } catch (Exception $ex) {
26 $error = $ex->getMessage();
29 // NOTE: If you enter an existing name, we're just treating it as an
30 // edit operation. This might be a little confusing.
32 if ($error !== null) {
33 if ($request->isFormPost()) {
34 // The user is creating a new property and picked a bad name. Give
35 // them an opportunity to fix it.
36 return $this->buildPropertyKeyResponse($cancel_uri, $error);
37 } else {
38 // The user is editing an invalid property.
39 return $this->newDialog()
40 ->setTitle(pht('Invalid Property'))
41 ->appendParagraph(
42 pht(
43 'The property name "%s" is invalid. This property can not '.
44 'be edited.',
45 $property_key))
46 ->appendParagraph($error)
47 ->addCancelButton($cancel_uri);
52 return $object->newAlmanacPropertyEditEngine()
53 ->addContextParameter('objectPHID')
54 ->addContextParameter('key')
55 ->setTargetObject($object)
56 ->setPropertyKey($property_key)
57 ->setController($this)
58 ->buildResponse();
61 private function buildPropertyKeyResponse($cancel_uri, $error) {
62 $viewer = $this->getViewer();
63 $request = $this->getRequest();
64 $v_key = $request->getStr('key');
66 if ($error !== null) {
67 $e_key = pht('Invalid');
68 } else {
69 $e_key = true;
72 $form = id(new AphrontFormView())
73 ->setUser($viewer)
74 ->appendChild(
75 id(new AphrontFormTextControl())
76 ->setName('key')
77 ->setLabel(pht('Name'))
78 ->setValue($v_key)
79 ->setError($e_key));
81 $errors = array();
82 if ($error !== null) {
83 $errors[] = $error;
86 return $this->newDialog()
87 ->setTitle(pht('Add Property'))
88 ->addHiddenInput('objectPHID', $request->getStr('objectPHID'))
89 ->setErrors($errors)
90 ->appendForm($form)
91 ->addSubmitButton(pht('Continue'))
92 ->addCancelButton($cancel_uri);