Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66678949
AphrontFormPolicyControl.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, Jun 12, 08:12
Size
2 KB
Mime Type
text/x-php
Expires
Fri, Jun 14, 08:12 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18259575
Attached To
rPH Phabricator
AphrontFormPolicyControl.php
View Options
<?php
final
class
AphrontFormPolicyControl
extends
AphrontFormControl
{
private
$object
;
private
$capability
;
private
$policies
;
public
function
setPolicyObject
(
PhabricatorPolicyInterface
$object
)
{
$this
->
object
=
$object
;
return
$this
;
}
public
function
setPolicies
(
array
$policies
)
{
assert_instances_of
(
$policies
,
'PhabricatorPolicy'
);
$this
->
policies
=
$policies
;
return
$this
;
}
public
function
setCapability
(
$capability
)
{
$this
->
capability
=
$capability
;
$labels
=
array
(
PhabricatorPolicyCapability
::
CAN_VIEW
=>
'Visible To'
,
PhabricatorPolicyCapability
::
CAN_EDIT
=>
'Editable By'
,
PhabricatorPolicyCapability
::
CAN_JOIN
=>
'Joinable By'
,
);
$this
->
setLabel
(
idx
(
$labels
,
$this
->
capability
,
'Unknown Policy'
));
return
$this
;
}
protected
function
getCustomControlClass
()
{
return
'aphront-form-control-policy'
;
}
protected
function
getOptions
()
{
$options
=
array
();
foreach
(
$this
->
policies
as
$policy
)
{
if
((
$policy
->
getPHID
()
==
PhabricatorPolicies
::
POLICY_PUBLIC
)
&&
(
$this
->
capability
!=
PhabricatorPolicyCapability
::
CAN_VIEW
))
{
// Never expose "Public" for anything except "Can View".
continue
;
}
$type_name
=
PhabricatorPolicyType
::
getPolicyTypeName
(
$policy
->
getType
());
$options
[
$type_name
][
$policy
->
getPHID
()]
=
$policy
->
getFullName
();
}
return
$options
;
}
protected
function
renderInput
()
{
if
(!
$this
->
object
)
{
throw
new
Exception
(
"Call setPolicyObject() before rendering!"
);
}
if
(!
$this
->
capability
)
{
throw
new
Exception
(
"Call setCapability() before rendering!"
);
}
$policy
=
$this
->
object
->
getPolicy
(
$this
->
capability
);
if
(!
$policy
)
{
// TODO: Make this configurable.
$policy
=
PhabricatorPolicies
::
POLICY_USER
;
}
$this
->
setValue
(
$policy
);
return
AphrontFormSelectControl
::
renderSelectTag
(
$this
->
getValue
(),
$this
->
getOptions
(),
array
(
'name'
=>
$this
->
getName
(),
'disabled'
=>
$this
->
getDisabled
()
?
'disabled'
:
null
,
'id'
=>
$this
->
getID
(),
));
}
}
Event Timeline
Log In to Comment