You are here

protected function TransactionTypeListBuilder::getTargetBundles in Transaction 8

Generates a render array of the applicable bundles.

Parameters

\Drupal\transaction\TransactionTypeInterface $transaction_type: The transaction type.

Return value

array A render array of the applicable bundle's label.

1 call to TransactionTypeListBuilder::getTargetBundles()
TransactionTypeListBuilder::buildRow in src/TransactionTypeListBuilder.php
Builds a row for an entity in the entity listing.

File

src/TransactionTypeListBuilder.php, line 123

Class

TransactionTypeListBuilder
Provides a entity list page for transaction types.

Namespace

Drupal\transaction

Code

protected function getTargetBundles(TransactionTypeInterface $transaction_type) {
  $bundles = $transaction_type
    ->getBundles();
  if (empty($bundles)) {
    return [
      'data' => [
        '#markup' => '<em>' . $this
          ->t('All') . '</em>',
        '#allowed_tags' => [
          'em',
        ],
      ],
    ];
  }

  // Compose bundle labels.
  if ($target_bundle_id = $this->entityTypeManager
    ->getDefinition($transaction_type
    ->getTargetEntityTypeId())
    ->getBundleEntityType()) {
    $target_bundle_storage = $this->entityTypeManager
      ->getStorage($target_bundle_id);
    foreach ($bundles as $key => $bundle) {
      $bundles[$key] = $target_bundle_storage
        ->load($bundle)
        ->label();
    }
  }
  return [
    'data' => [
      '#markup' => implode(', ', $bundles),
    ],
  ];
}