Page MenuHomePhabricator
Paste P1895

AddCommentHeraldAction.php
ActivePublic

Authored by epriestley on Nov 25 2015, 8:59 PM.
Tags
Referenced Files
F1003226: AddCommentHeraldAction.php
Nov 25 2015, 8:59 PM
Subscribers
Tokens
"Like" token, awarded by kaw."Piece of Eight" token, awarded by chad.
<?php
final class AddCommentHeraldAction
extends HeraldAction {
const ACTIONCONST = 'custom.transactions.comment';
const DO_COMMENT = 'do.comment';
public function getHeraldActionName() {
return pht('Add comment');
}
public function getActionGroupKey() {
return HeraldUtilityActionGroup::ACTIONGROUPKEY;
}
public function supportsObject($object) {
if (!($object instanceof PhabricatorApplicationTransactionInterface)) {
return false;
}
$xaction = $object->getApplicationTransactionTemplate();
try {
$comment = $xaction->getApplicationTransactionCommentObject();
if (!$comment) {
return false;
}
} catch (Exception $ex) {
return false;
}
return true;
}
public function supportsRuleType($rule_type) {
return true;
}
public function applyEffect($object, HeraldEffect $effect) {
$adapter = $this->getAdapter();
$comment_text = $effect->getTarget();
$comment = $adapter->newTransaction()
->getApplicationTransactionCommentObject()
->setContent($comment_text);
$xaction = $adapter->newTransaction()
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
->attachComment($comment);
$adapter->queueTransaction($xaction);
$this->logEffect(self::DO_COMMENT);
}
public function getHeraldActionStandardType() {
return self::STANDARD_TEXT;
}
public function renderActionDescription($value) {
return pht('Add comment: %s', $value);
}
protected function getActionEffectMap() {
return array(
self::DO_COMMENT => array(
'icon' => 'fa-comment',
'color' => 'blue',
'name' => pht('Added comment.'),
),
);
}
protected function renderActionEffectDescription($type, $data) {
switch ($type) {
case self::DO_COMMENT:
return pht('Added comment.');
}
}
}