You are here

public function UserPointsTransactor::getExecutionIndications in User Points 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 BalanceTransactor::getExecutionIndications

File

src/Plugin/Transaction/UserPointsTransactor.php, line 107

Class

UserPointsTransactor
Transactor for user points type transactions.

Namespace

Drupal\userpoints\Plugin\Transaction

Code

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' => abs($transaction
      ->get($settings['amount'])->value),
  ];
  $t_options = $langcode ? [
    'langcode' => $langcode,
  ] : [];
  if ($amount > 0) {
    $indication = $this
      ->t('The user will gain @amount points.', $t_args, $t_options);
  }
  elseif ($amount < 0) {
    $indication = $this
      ->t('The user will loss @amount points.', $t_args, $t_options);
  }
  else {
    $indication = $this
      ->t('The current user points balance will not be altered.', [], $t_options);
  }
  return $indication;
}