Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1004998
CountTransactionsHeraldAction.php
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
joshuaspence
Nov 27 2015, 9:03 AM
2015-11-27 09:03:47 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
CountTransactionsHeraldAction.php
View Options
<?php
/**
* Example of how to use a HeraldAction instead of an event listener.
*/
final
class
CountTransactionsHeraldAction
extends
HeraldAction
{
const
ACTIONCONST
=
'custom.transactions.count'
;
const
DO_COUNT
=
'do.count'
;
public
function
getHeraldActionName
()
{
return
pht
(
'Count task transactions'
);
}
public
function
getActionGroupKey
()
{
return
HeraldUtilityActionGroup
::
ACTIONGROUPKEY
;
}
public
function
supportsObject
(
$object
)
{
// You can modify this method to let your rule run on other types of
// objects that support Herald, like Differential revisions.
return
(
$object
instanceof
ManiphestTask
);
}
public
function
supportsRuleType
(
$rule_type
)
{
switch
(
$rule_type
)
{
case
HeraldRuleTypeConfig
::
RULE_TYPE_GLOBAL
:
case
HeraldRuleTypeConfig
::
RULE_TYPE_OBJECT
:
case
HeraldRuleTypeConfig
::
RULE_TYPE_PERSONAL
:
return
true
;
}
}
public
function
applyEffect
(
$object
,
HeraldEffect
$effect
)
{
$adapter
=
$this
->
getAdapter
();
// NOTE: $object is the object being edited. If you didn't change the
// implementation of `supportsObject()`, it's a ManiphestTask.
// Transactions which were just applied.
$applied_xactions
=
$adapter
->
getAppliedTransactions
();
$comment_text
=
pht
(
'This edit applied %s transactions.'
,
phutil_count
(
$applied_xactions
));
$comment
=
$adapter
->
newTransaction
()
->
getApplicationTransactionCommentObject
()
->
setContent
(
$comment_text
);
$xaction
=
$adapter
->
newTransaction
()
->
setTransactionType
(
PhabricatorTransactions
::
TYPE_COMMENT
)
->
attachComment
(
$comment
);
// Use queueTransaction() to queue up transactions to be applied.
$adapter
->
queueTransaction
(
$xaction
);
// This makes the effect observable in the Herald transcript.
$this
->
logEffect
(
self
::
DO_COUNT
);
}
public
function
getHeraldActionStandardType
()
{
// You can change this to give your action an editable value in the UI,
// like how "Add Subscribers: ..." allows you to choose subscribers to add.
// This might let you make a more modular/flexible action.
return
self
::
STANDARD_NONE
;
}
public
function
renderActionDescription
(
$value
)
{
return
pht
(
'Count task transactions'
);
}
protected
function
getActionEffectMap
()
{
return
array
(
self
::
DO_COUNT
=>
array
(
'icon'
=>
'fa-sort-numeric-asc'
,
'color'
=>
'violet'
,
'name'
=>
pht
(
'Counted transactions.'
),
),
);
}
protected
function
renderActionEffectDescription
(
$type
,
$data
)
{
switch
(
$type
)
{
case
self
::
DO_COUNT
:
return
pht
(
'Added comment.'
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/cq/5l/lu6cnh5od4t65vzy
Default Alt Text
CountTransactionsHeraldAction.php (2 KB)
Attached To
Mode
P1896 CountTransactionsHeraldAction.php
Attached
Detach File
Event Timeline
Log In to Comment