You are here

public function TransactorBase::getResultMessage in Transaction 8

Compose a message that describes the execution result of a transaction.

Parameters

\Drupal\transaction\TransactionInterface $transaction: The executed transaction for which to compose the result message.

string $langcode: (optional) The language to use in message composition. Defaults to the current content language.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup Translatable markup with the execution result message, FALSE if transaction execution was never called.

Overrides TransactorPluginInterface::getResultMessage

File

src/TransactorBase.php, line 735

Class

TransactorBase
Provides a base class for transactor plugins.

Namespace

Drupal\transaction

Code

public function getResultMessage(TransactionInterface $transaction, $langcode = NULL) {
  if (!($result_code = $transaction
    ->getResultCode())) {
    return FALSE;
  }
  $t_args = [];
  $t_options = $langcode ? [
    'langcode' => $langcode,
  ] : [];
  if ($result_code > 0) {
    $message = $this
      ->t('Transaction executed successfully.', $t_args, $t_options);
  }
  else {
    $message = $transaction
      ->isPending() ? $this
      ->t('There was a recoverable error in the transaction execution.', $t_args, $t_options) : $this
      ->t('There was a fatal error in the transaction execution.', $t_args, $t_options);
  }
  return $message;
}