Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / almanac / controller / AlmanacServiceEditController.php
blob710e27a966cf7915e6250322059f4610f3295d80
1 <?php
3 final class AlmanacServiceEditController
4 extends AlmanacServiceController {
6 public function handleRequest(AphrontRequest $request) {
7 $engine = id(new AlmanacServiceEditEngine())
8 ->setController($this);
10 $id = $request->getURIData('id');
11 if (!$id) {
12 $this->requireApplicationCapability(
13 AlmanacCreateServicesCapability::CAPABILITY);
15 $list_uri = $this->getApplicationURI('service/');
17 $service_type = $request->getStr('serviceType');
18 $service_types = AlmanacServiceType::getAllServiceTypes();
19 if (empty($service_types[$service_type])) {
20 return $this->buildServiceTypeResponse($list_uri);
23 $engine
24 ->addContextParameter('serviceType', $service_type)
25 ->setServiceType($service_type);
28 return $engine->buildResponse();
31 private function buildServiceTypeResponse($cancel_uri) {
32 $service_types = AlmanacServiceType::getAllServiceTypes();
34 $request = $this->getRequest();
35 $viewer = $this->getViewer();
37 $e_service = null;
38 $errors = array();
39 if ($request->isFormPost()) {
40 $e_service = pht('Required');
41 $errors[] = pht(
42 'To create a new service, you must select a service type.');
45 list($can_cluster, $cluster_link) = $this->explainApplicationCapability(
46 AlmanacManageClusterServicesCapability::CAPABILITY,
47 pht('You have permission to create cluster services.'),
48 pht('You do not have permission to create new cluster services.'));
50 $type_control = id(new AphrontFormRadioButtonControl())
51 ->setLabel(pht('Service Type'))
52 ->setName('serviceType')
53 ->setError($e_service);
55 foreach ($service_types as $service_type) {
56 $is_cluster = $service_type->isClusterServiceType();
57 $is_disabled = ($is_cluster && !$can_cluster);
59 if ($is_cluster) {
60 $extra = $cluster_link;
61 } else {
62 $extra = null;
65 $type_control->addButton(
66 $service_type->getServiceTypeConstant(),
67 $service_type->getServiceTypeName(),
68 array(
69 $service_type->getServiceTypeDescription(),
70 $extra,
72 $is_disabled ? 'disabled' : null,
73 $is_disabled);
76 $crumbs = $this->buildApplicationCrumbs();
77 $crumbs->addTextCrumb(pht('Create Service'));
78 $crumbs->setBorder(true);
80 $title = pht('Choose Service Type');
81 $header = id(new PHUIHeaderView())
82 ->setHeader(pht('Create Service'))
83 ->setHeaderIcon('fa-plus-square');
85 $form = id(new AphrontFormView())
86 ->setUser($viewer)
87 ->appendChild($type_control)
88 ->appendChild(
89 id(new AphrontFormSubmitControl())
90 ->setValue(pht('Continue'))
91 ->addCancelButton($cancel_uri));
93 $box = id(new PHUIObjectBoxView())
94 ->setFormErrors($errors)
95 ->setHeaderText(pht('Service'))
96 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
97 ->setForm($form);
99 $view = id(new PHUITwoColumnView())
100 ->setHeader($header)
101 ->setFooter(array(
102 $box,
105 return $this->newPage()
106 ->setTitle($title)
107 ->setCrumbs($crumbs)
108 ->appendChild($view);