You are here

public function TransactorHandler::composeDetails in Transaction 8

Compose human readable details for the given transaction.

Parameters

\Drupal\transaction\TransactionInterface $transaction: The transaction to detail.

string $langcode: (optional) For which language the transaction details should be composed, defaults to the current content language.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup[] An array of translatable markup objects representing each one a line detailing the transaction. Empty array if no details were composed.

Overrides TransactorHandlerInterface::composeDetails

File

src/TransactorHandler.php, line 241

Class

TransactorHandler
Transactor entity handler.

Namespace

Drupal\transaction

Code

public function composeDetails(TransactionInterface $transaction, $langcode = NULL) {

  // Details from transactor.
  $details = $transaction
    ->getType()
    ->getPlugin()
    ->getTransactionDetails($transaction, $langcode);

  // Details from operation details template.
  if ($operation = $transaction
    ->getOperation()) {
    $token_options = [
      'clear' => TRUE,
    ];
    if ($langcode) {
      $token_options['langcode'] = $langcode;
    }
    $target_entity = $transaction
      ->getTargetEntity();
    $target_entity_type_id = $target_entity
      ->getEntityTypeId();
    $token_data = [
      'transaction' => $transaction,
      TransactorHandler::getTokenContextFromEntityTypeId($target_entity_type_id) => $target_entity,
    ];
    foreach ($operation
      ->getDetails() as $detail) {
      $details[] = PlainTextOutput::renderFromHtml($this->token
        ->replace($detail, $token_data, $token_options));
    }
  }
  return $details;
}