Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96476513
AlmanacServiceEditController.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Dec 27, 03:03
Size
2 KB
Mime Type
text/x-php
Expires
Sun, Dec 29, 03:03 (2 d)
Engine
blob
Format
Raw Data
Handle
23189977
Attached To
rPH Phabricator
AlmanacServiceEditController.php
View Options
<?php
final
class
AlmanacServiceEditController
extends
AlmanacServiceController
{
public
function
handleRequest
(
AphrontRequest
$request
)
{
$engine
=
id
(
new
AlmanacServiceEditEngine
())
->
setController
(
$this
);
$id
=
$request
->
getURIData
(
'id'
);
if
(!
$id
)
{
$this
->
requireApplicationCapability
(
AlmanacCreateServicesCapability
::
CAPABILITY
);
$list_uri
=
$this
->
getApplicationURI
(
'service/'
);
$service_type
=
$request
->
getStr
(
'serviceType'
);
$service_types
=
AlmanacServiceType
::
getAllServiceTypes
();
if
(
empty
(
$service_types
[
$service_type
]))
{
return
$this
->
buildServiceTypeResponse
(
$list_uri
);
}
$engine
->
addContextParameter
(
'serviceType'
,
$service_type
)
->
setServiceType
(
$service_type
);
}
return
$engine
->
buildResponse
();
}
private
function
buildServiceTypeResponse
(
$cancel_uri
)
{
$service_types
=
AlmanacServiceType
::
getAllServiceTypes
();
$request
=
$this
->
getRequest
();
$viewer
=
$this
->
getViewer
();
$e_service
=
null
;
$errors
=
array
();
if
(
$request
->
isFormPost
())
{
$e_service
=
pht
(
'Required'
);
$errors
[]
=
pht
(
'To create a new service, you must select a service type.'
);
}
list
(
$can_cluster
,
$cluster_link
)
=
$this
->
explainApplicationCapability
(
AlmanacManageClusterServicesCapability
::
CAPABILITY
,
pht
(
'You have permission to create cluster services.'
),
pht
(
'You do not have permission to create new cluster services.'
));
$type_control
=
id
(
new
AphrontFormRadioButtonControl
())
->
setLabel
(
pht
(
'Service Type'
))
->
setName
(
'serviceType'
)
->
setError
(
$e_service
);
foreach
(
$service_types
as
$service_type
)
{
$is_cluster
=
$service_type
->
isClusterServiceType
();
$is_disabled
=
(
$is_cluster
&&
!
$can_cluster
);
if
(
$is_cluster
)
{
$extra
=
$cluster_link
;
}
else
{
$extra
=
null
;
}
$type_control
->
addButton
(
$service_type
->
getServiceTypeConstant
(),
$service_type
->
getServiceTypeName
(),
array
(
$service_type
->
getServiceTypeDescription
(),
$extra
,
),
$is_disabled
?
'disabled'
:
null
,
$is_disabled
);
}
$crumbs
=
$this
->
buildApplicationCrumbs
();
$crumbs
->
addTextCrumb
(
pht
(
'Create Service'
));
$title
=
pht
(
'Choose Service Type'
);
$form
=
id
(
new
AphrontFormView
())
->
setUser
(
$viewer
)
->
appendChild
(
$type_control
)
->
appendChild
(
id
(
new
AphrontFormSubmitControl
())
->
setValue
(
pht
(
'Continue'
))
->
addCancelButton
(
$cancel_uri
));
$box
=
id
(
new
PHUIObjectBoxView
())
->
setFormErrors
(
$errors
)
->
setHeaderText
(
$title
)
->
setForm
(
$form
);
return
$this
->
newPage
()
->
setTitle
(
$title
)
->
setCrumbs
(
$crumbs
)
->
appendChild
(
$box
);
}
}
Event Timeline
Log In to Comment