Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P2080
CopyPHIDAction.php
Active
Public
Actions
Authored by
avivey
on Dec 7 2017, 12:47 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F5313198: CopyPHIDAction.php
Dec 7 2017, 12:47 PM
2017-12-07 12:47:55 (UTC+0)
Subscribers
None
<?php
/**
* Dump this in /src/extensions, and get a "Copy PHID to clipboard" action on every page.
*/
final
class
CopyPHIDAction
extends
PhabricatorAutoEventListener
{
public
function
register
()
{
$this
->
listen
(
PhabricatorEventType
::
TYPE_UI_DIDRENDERACTIONS
);
}
public
function
handleEvent
(
PhutilEvent
$event
)
{
switch
(
$event
->
getType
())
{
case
PhabricatorEventType
::
TYPE_UI_DIDRENDERACTIONS
:
$this
->
handleActionEvent
(
$event
);
break
;
}
}
private
function
handleActionEvent
(
$event
)
{
$viewer
=
$event
->
getUser
();
$object
=
$event
->
getValue
(
'object'
);
if
(!
$object
||
!
$object
->
getPHID
())
{
return
;
}
Javelin
::
initBehavior
(
'phabricator-clipboard-copy'
);
$actions
=
$event
->
getValue
(
'actions'
);
$actions
[]
=
id
(
new
PhabricatorActionView
())
->
setHref
(
'#'
)
->
setRenderAsForm
(
true
)
->
setName
(
pht
(
'Copy PHID (%s)'
,
phid_get_type
(
$object
->
getPHID
())))
->
setIcon
(
'fa-clipboard'
)
->
addSigil
(
'clipboard-copy'
)
->
setMetadata
(
array
(
'text'
=>
$object
->
getPHID
()));
$event
->
setValue
(
'actions'
,
$actions
);
}
}
Event Timeline
avivey
created this paste.
Dec 7 2017, 12:47 PM
2017-12-07 12:47:55 (UTC+0)
avivey
mentioned this in
T13157: Provide more advanced tools for developing against Phabricator and discovering PHIDs
.
Jun 21 2018, 7:47 PM
2018-06-21 19:47:06 (UTC+0)
Log In to Comment