public function UserPointsTransactor::getTransactionDescription in User Points 8
Compose a human readable description for the given transaction.
Parameters
\Drupal\transaction\TransactionInterface $transaction: The transaction to describe.
string $langcode: (optional) For which language the transaction description should be composed, defaults to the current content language.
Return value
string|\Drupal\Core\StringTranslation\TranslatableMarkup A string or translatable markup with the generated description.
Overrides BalanceTransactor::getTransactionDescription
File
- src/
Plugin/ Transaction/ UserPointsTransactor.php, line 83
Class
- UserPointsTransactor
- Transactor for user points type transactions.
Namespace
Drupal\userpoints\Plugin\TransactionCode
public function getTransactionDescription(TransactionInterface $transaction, $langcode = NULL) {
$settings = $transaction
->getType()
->getPluginSettings();
// Transaction amount.
$amount = $transaction
->get($settings['amount'])->value;
$t_options = $langcode ? [
'langcode' => $langcode,
] : [];
$t_args = [
'@status' => $transaction
->isPending() ? $this
->t('(pending)') : '',
];
if ($amount > 0) {
$description = $this
->t('Points credit @status', $t_args, $t_options);
}
elseif ($amount < 0) {
$description = $this
->t('Points debit @status', $t_args, $t_options);
}
else {
$description = $this
->t('Zero points transaction @status', $t_args, $t_options);
}
return $description;
}