public function BalanceTransactor::getExecutionIndications in Transaction 8
Compose a messsage with execution indications for the given transaction.
This message is commonly shown to the users upon transaction execution.
Parameters
\Drupal\transaction\TransactionInterface $transaction: The pending transaction to compose indications about.
string $langcode: (optional) For which language the execution indications should be composed, defaults to the current content language.
Return value
string|\Drupal\Core\StringTranslation\TranslatableMarkup A string or translatable markup with the generated message.
Overrides TransactorBase::getExecutionIndications
File
- src/
Plugin/ Transaction/ BalanceTransactor.php, line 122
Class
- BalanceTransactor
- Transactor for accounting type transactions.
Namespace
Drupal\transaction\Plugin\TransactionCode
public function getExecutionIndications(TransactionInterface $transaction, $langcode = NULL) {
$settings = $transaction
->getType()
->getPluginSettings();
// Transaction amount.
$amount = $transaction
->get($settings['amount'])->value;
// @todo pretty print of amount according to default display settings
$t_args = [
'@amount' => $transaction
->get($settings['amount'])
->getString(),
];
$t_options = $langcode ? [
'langcode' => $langcode,
] : [];
if ($amount > 0) {
$indication = $this
->t('The current balance will increase by @amount.', $t_args, $t_options);
}
elseif ($amount < 0) {
$indication = $this
->t('The current balance will decrease by @amount.', $t_args, $t_options);
}
else {
$indication = $this
->t('The current balance will not be altered.', [], $t_options);
}
return $indication . ' ' . parent::getExecutionIndications($transaction, $langcode);
}