Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F100209116
AlmanacPropertyEditController.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
Wed, Jan 29, 01:30
Size
2 KB
Mime Type
text/x-php
Expires
Fri, Jan 31, 01:30 (2 d)
Engine
blob
Format
Raw Data
Handle
23887233
Attached To
rPH Phabricator
AlmanacPropertyEditController.php
View Options
<?php
final
class
AlmanacPropertyEditController
extends
AlmanacDeviceController
{
public
function
handleRequest
(
AphrontRequest
$request
)
{
$viewer
=
$request
->
getViewer
();
$object
=
id
(
new
PhabricatorObjectQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
array
(
$request
->
getStr
(
'objectPHID'
)))
->
requireCapabilities
(
array
(
PhabricatorPolicyCapability
::
CAN_VIEW
,
PhabricatorPolicyCapability
::
CAN_EDIT
,
))
->
executeOne
();
if
(!
$object
)
{
return
new
Aphront404Response
();
}
if
(!(
$object
instanceof
AlmanacPropertyInterface
))
{
return
new
Aphront404Response
();
}
$cancel_uri
=
$object
->
getURI
();
$property_key
=
$request
->
getStr
(
'key'
);
if
(!
strlen
(
$property_key
))
{
return
$this
->
buildPropertyKeyResponse
(
$cancel_uri
,
null
);
}
else
{
$error
=
null
;
try
{
AlmanacNames
::
validateName
(
$property_key
);
}
catch
(
Exception
$ex
)
{
$error
=
$ex
->
getMessage
();
}
// NOTE: If you enter an existing name, we're just treating it as an
// edit operation. This might be a little confusing.
if
(
$error
!==
null
)
{
if
(
$request
->
isFormPost
())
{
// The user is creating a new property and picked a bad name. Give
// them an opportunity to fix it.
return
$this
->
buildPropertyKeyResponse
(
$cancel_uri
,
$error
);
}
else
{
// The user is editing an invalid property.
return
$this
->
newDialog
()
->
setTitle
(
pht
(
'Invalid Property'
))
->
appendParagraph
(
pht
(
'The property name "%s" is invalid. This property can not '
.
'be edited.'
,
$property_key
))
->
appendParagraph
(
$error
)
->
addCancelButton
(
$cancel_uri
);
}
}
}
return
$object
->
newAlmanacPropertyEditEngine
()
->
addContextParameter
(
'objectPHID'
)
->
addContextParameter
(
'key'
)
->
setTargetObject
(
$object
)
->
setPropertyKey
(
$property_key
)
->
setController
(
$this
)
->
buildResponse
();
}
private
function
buildPropertyKeyResponse
(
$cancel_uri
,
$error
)
{
$viewer
=
$this
->
getViewer
();
$request
=
$this
->
getRequest
();
$v_key
=
$request
->
getStr
(
'key'
);
if
(
$error
!==
null
)
{
$e_key
=
pht
(
'Invalid'
);
}
else
{
$e_key
=
true
;
}
$form
=
id
(
new
AphrontFormView
())
->
setUser
(
$viewer
)
->
appendChild
(
id
(
new
AphrontFormTextControl
())
->
setName
(
'key'
)
->
setLabel
(
pht
(
'Name'
))
->
setValue
(
$v_key
)
->
setError
(
$e_key
));
$errors
=
array
();
if
(
$error
!==
null
)
{
$errors
[]
=
$error
;
}
return
$this
->
newDialog
()
->
setTitle
(
pht
(
'Add Property'
))
->
addHiddenInput
(
'objectPHID'
,
$request
->
getStr
(
'objectPHID'
))
->
setErrors
(
$errors
)
->
appendForm
(
$form
)
->
addSubmitButton
(
pht
(
'Continue'
))
->
addCancelButton
(
$cancel_uri
);
}
}
Event Timeline
Log In to Comment