You are here

public function TransactorBase::getTransactionDescription in Transaction 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 TransactorPluginInterface::getTransactionDescription

1 call to TransactorBase::getTransactionDescription()
BalanceTransactor::getTransactionDescription in src/Plugin/Transaction/BalanceTransactor.php
Compose a human readable description for the given transaction.
1 method overrides TransactorBase::getTransactionDescription()
BalanceTransactor::getTransactionDescription in src/Plugin/Transaction/BalanceTransactor.php
Compose a human readable description for the given transaction.

File

src/TransactorBase.php, line 757

Class

TransactorBase
Provides a base class for transactor plugins.

Namespace

Drupal\transaction

Code

public function getTransactionDescription(TransactionInterface $transaction, $langcode = NULL) {
  $t_options = $langcode ? [
    'langcode' => $langcode,
  ] : [];
  if ($transaction
    ->isNew()) {
    $description = $transaction
      ->isPending() ? $this
      ->t('Unsaved transaction (pending)', [], $t_options) : $this
      ->t('Unsaved transaction', [], $t_options);
  }
  else {
    $t_args = [
      '@number' => $transaction
        ->id(),
    ];
    $description = $transaction
      ->isPending() ? $this
      ->t('Transaction @number (pending)', $t_args, $t_options) : $this
      ->t('Transaction @number', $t_args, $t_options);
  }
  return $description;
}