You are here

public static function TransactionOperationListBuilder::createInstance in Transaction 8

Instantiates a new instance of this entity handler.

This is a factory method that returns a new instance of this object. The factory should pass any needed dependencies into the constructor of this object, but not the container itself. Every call to this method must return a new instance of this object; that is, it may not implement a singleton.

Parameters

\Symfony\Component\DependencyInjection\ContainerInterface $container: The service container this object should use.

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

Return value

static A new instance of the entity handler.

Overrides EntityListBuilder::createInstance

File

src/TransactionOperationListBuilder.php, line 43

Class

TransactionOperationListBuilder
Provides a entity list page for transaction operations.

Namespace

Drupal\transaction

Code

public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {

  // Get the transaction type id from request or route options.
  if ($transaction_type = $container
    ->get('request_stack')
    ->getCurrentRequest()
    ->get('transaction_type')) {
    $transaction_type_id = is_string($transaction_type) ? $transaction_type : $transaction_type
      ->id();
  }
  else {
    $route_options = $container
      ->get('current_route_match')
      ->getRouteObject()
      ->getOptions();
    $transaction_type_id = isset($route_options['_transaction_transaction_type_id']) ? $route_options['_transaction_transaction_type_id'] : '';
  }
  return new static($entity_type, $container
    ->get('entity_type.manager')
    ->getStorage($entity_type
    ->id()), $transaction_type_id);
}