You are here

public function TransactionListBuilder::__construct in Transaction 8

Constructs a new TransactionListBuilder object.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition.

\Drupal\transaction\TransactorPluginManagerInterface $transactor_manager: The transactor plugin manager.

\Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager: The entity type manager.

\Drupal\Core\Datetime\DateFormatterInterface $date_formatter: The date formatter service.

\Symfony\Component\HttpFoundation\Request $current_request: The currently active request object.

\Drupal\Core\Routing\RouteMatchInterface $current_route_match: The current route match.

Overrides EntityListBuilder::__construct

File

src/TransactionListBuilder.php, line 66

Class

TransactionListBuilder
Provides a entity list page for transactions.

Namespace

Drupal\transaction

Code

public function __construct(EntityTypeInterface $entity_type, TransactorPluginManagerInterface $transactor_manager, EntityTypeManagerInterface $entity_type_manager, DateFormatterInterface $date_formatter, Request $current_request, RouteMatchInterface $current_route_match) {
  try {
    parent::__construct($entity_type, $entity_type_manager
      ->getStorage('transaction'));
    $this->dateFormatter = $date_formatter;
    $current_route = $current_route_match
      ->getRouteObject();

    // This list builder can be targeted by multiple routes. When some
    // argument are not present in the request, we try to get from the route
    // options.

    /* @see \Drupal\transaction\Routing\RouteSubscriber */
    if (!($this->transactionType = $current_request
      ->get('transaction_type')) && ($transaction_type_id = $current_route
      ->getOption('_transaction_transaction_type_id'))) {
      $this->transactionType = $entity_type_manager
        ->getStorage('transaction_type')
        ->load($transaction_type_id);
    }
    if (!($this->targetEntity = $current_request
      ->get('target_entity')) && ($target_entity_type_id = $current_route
      ->getOption('_transaction_target_entity_type_id'))) {
      $this->targetEntity = $current_request
        ->get($target_entity_type_id);
    }

    // Set transactor fields.
    if ($this->transactionType && ($plugin_info = $transactor_manager
      ->getTransactor($this->transactionType
      ->getPluginId()))) {
      foreach ($plugin_info['transaction_fields'] as $transactor_field_info) {
        if (!empty($transactor_field_info['list'])) {
          $this->extraFields[$transactor_field_info['name']] = $transactor_field_info['title'];
        }
      }
    }
  } catch (InvalidPluginDefinitionException $e) {

    // The transaction or transaction type storage is not present?
  }
}