Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90912333
PhabricatorObjectRelationshipList.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
Tue, Nov 5, 22:28
Size
2 KB
Mime Type
text/x-php
Expires
Thu, Nov 7, 22:28 (2 d)
Engine
blob
Format
Raw Data
Handle
22157523
Attached To
rPH Phabricator
PhabricatorObjectRelationshipList.php
View Options
<?php
final
class
PhabricatorObjectRelationshipList
extends
Phobject
{
private
$viewer
;
private
$object
;
private
$relationships
;
public
function
setViewer
(
PhabricatorUser
$viewer
)
{
$this
->
viewer
=
$viewer
;
return
$this
;
}
public
function
getViewer
()
{
if
(
$this
->
viewer
===
null
)
{
throw
new
PhutilInvalidStateException
(
'setViewer'
);
}
return
$this
->
viewer
;
}
public
function
setObject
(
$object
)
{
$this
->
object
=
$object
;
return
$this
;
}
public
function
getObject
()
{
if
(
$this
->
object
===
null
)
{
throw
new
PhutilInvalidStateException
(
'setObject'
);
}
return
$this
->
object
;
}
public
function
setRelationships
(
array
$relationships
)
{
assert_instances_of
(
$relationships
,
'PhabricatorObjectRelationship'
);
$this
->
relationships
=
$relationships
;
return
$this
;
}
public
function
getRelationships
()
{
if
(
$this
->
relationships
===
null
)
{
throw
new
PhutilInvalidStateException
(
'setRelationships'
);
}
return
$this
->
relationships
;
}
public
function
newActionMenu
()
{
$relationships
=
$this
->
getRelationships
();
$object
=
$this
->
getObject
();
$actions
=
array
();
foreach
(
$relationships
as
$key
=>
$relationship
)
{
if
(!
$relationship
->
shouldAppearInActionMenu
())
{
continue
;
}
$actions
[
$key
]
=
$relationship
->
newAction
(
$object
);
}
if
(!
$actions
)
{
return
null
;
}
$actions
=
msort
(
$actions
,
'getName'
);
return
id
(
new
PhabricatorActionView
())
->
setName
(
pht
(
'Edit Related Objects...'
))
->
setIcon
(
'fa-link'
)
->
setSubmenu
(
$actions
);
}
public
static
function
newForObject
(
PhabricatorUser
$viewer
,
$object
)
{
$relationships
=
PhabricatorObjectRelationship
::
getAllRelationships
();
$results
=
array
();
foreach
(
$relationships
as
$key
=>
$relationship
)
{
$relationship
=
clone
$relationship
;
$relationship
->
setViewer
(
$viewer
);
if
(!
$relationship
->
isEnabledForObject
(
$object
))
{
continue
;
}
$results
[
$key
]
=
$relationship
;
}
return
id
(
new
self
())
->
setViewer
(
$viewer
)
->
setObject
(
$object
)
->
setRelationships
(
$results
);
}
}
Event Timeline
Log In to Comment