3 final class AlmanacPropertyEditController
4 extends AlmanacPropertyController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $request->getViewer();
9 $response = $this->loadPropertyObject();
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);
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);
38 // The user is editing an invalid property.
39 return $this->newDialog()
40 ->setTitle(pht('Invalid Property'))
43 'The property name "%s" is invalid. This property can not '.
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)
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');
72 $form = id(new AphrontFormView())
75 id(new AphrontFormTextControl())
77 ->setLabel(pht('Name'))
82 if ($error !== null) {
86 return $this->newDialog()
87 ->setTitle(pht('Add Property'))
88 ->addHiddenInput('objectPHID', $request->getStr('objectPHID'))
91 ->addSubmitButton(pht('Continue'))
92 ->addCancelButton($cancel_uri);