3 final class AlmanacBindingEditController
4 extends AlmanacServiceController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $request->getViewer();
9 $id = $request->getURIData('id');
11 $binding = id(new AlmanacBindingQuery())
14 ->requireCapabilities(
16 PhabricatorPolicyCapability
::CAN_VIEW
,
17 PhabricatorPolicyCapability
::CAN_EDIT
,
21 return new Aphront404Response();
24 $service = $binding->getService();
27 $service_uri = $service->getURI();
28 $cancel_uri = $binding->getURI();
29 $title = pht('Edit Binding');
30 $save_button = pht('Save Changes');
32 $service = id(new AlmanacServiceQuery())
34 ->withIDs(array($request->getStr('serviceID')))
35 ->requireCapabilities(
37 PhabricatorPolicyCapability
::CAN_VIEW
,
38 PhabricatorPolicyCapability
::CAN_EDIT
,
42 $binding = AlmanacBinding
::initializeNewBinding($service);
45 $service_uri = $service->getURI();
46 $cancel_uri = $service_uri;
47 $title = pht('Create Binding');
48 $save_button = pht('Create Binding');
51 $v_interface = array();
52 if ($binding->getInterfacePHID()) {
53 $v_interface = array($binding->getInterfacePHID());
57 $validation_exception = null;
58 if ($request->isFormPost()) {
59 $v_interface = $request->getArr('interfacePHIDs');
61 $type_interface = AlmanacBindingInterfaceTransaction
::TRANSACTIONTYPE
;
65 $xactions[] = id(new AlmanacBindingTransaction())
66 ->setTransactionType($type_interface)
67 ->setNewValue(head($v_interface));
69 $editor = id(new AlmanacBindingEditor())
71 ->setContentSourceFromRequest($request)
72 ->setContinueOnNoEffect(true);
75 $editor->applyTransactions($binding, $xactions);
77 $binding_uri = $binding->getURI();
78 return id(new AphrontRedirectResponse())->setURI($binding_uri);
79 } catch (PhabricatorApplicationTransactionValidationException
$ex) {
80 $validation_exception = $ex;
81 $e_interface = $ex->getShortMessage($type_interface);
85 $form = id(new AphrontFormView())
88 id(new AphrontFormTokenizerControl())
89 ->setName('interfacePHIDs')
90 ->setLabel(pht('Interface'))
92 ->setDatasource(new AlmanacInterfaceDatasource())
93 ->setValue($v_interface)
94 ->setError($e_interface))
96 id(new AphrontFormSubmitControl())
97 ->addCancelButton($cancel_uri)
98 ->setValue($save_button));
100 $box = id(new PHUIObjectBoxView())
101 ->setValidationException($validation_exception)
102 ->setHeaderText(pht('Binding'))
103 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
104 ->appendChild($form);
106 $crumbs = $this->buildApplicationCrumbs();
107 $crumbs->addTextCrumb($service->getName(), $service_uri);
109 $crumbs->addTextCrumb(pht('Create Binding'));
110 $header = id(new PHUIHeaderView())
111 ->setHeader(pht('Create Binding'))
112 ->setHeaderIcon('fa-plus-square');
114 $crumbs->addTextCrumb(pht('Edit Binding'));
115 $header = id(new PHUIHeaderView())
116 ->setHeader(pht('Create Binding'))
117 ->setHeaderIcon('fa-pencil');
119 $crumbs->setBorder(true);
121 $view = id(new PHUITwoColumnView())
127 return $this->newPage()
130 ->appendChild($view);