You are here

public function RoutingTransactionNameSubscriber::addTransactionNamesToRoutes in New Relic 8

Same name and namespace in other branches
  1. 2.x src/EventSubscriber/RoutingTransactionNameSubscriber.php \Drupal\new_relic_rpm\EventSubscriber\RoutingTransactionNameSubscriber::addTransactionNamesToRoutes()
  2. 2.0.x src/EventSubscriber/RoutingTransactionNameSubscriber.php \Drupal\new_relic_rpm\EventSubscriber\RoutingTransactionNameSubscriber::addTransactionNamesToRoutes()

Add transaction names/callbacks to individual routes.

File

src/EventSubscriber/RoutingTransactionNameSubscriber.php, line 34

Class

RoutingTransactionNameSubscriber
Enhances routes with a transaction name or transaction name callback.

Namespace

Drupal\new_relic_rpm\EventSubscriber

Code

public function addTransactionNamesToRoutes(RouteBuildEvent $event) {
  $collection = $event
    ->getRouteCollection();

  // Set a transaction name for the route.
  foreach ($collection as $route_name => $route) {
    $route
      ->setDefault('_transaction_name', $route_name);
  }
  $entity_bundle_routes = [
    'entity.node.canonical',
    'entity.node.edit_form',
    'entity.taxonomy_term.canonical',
    'entity.taxonomy_term.edit_form',
    'entity.taxonomy_term.add_form',
  ];
  foreach ($entity_bundle_routes as $entity_bundle_route) {
    if ($route = $collection
      ->get($entity_bundle_route)) {
      $route
        ->setDefault('_transaction_name_callback', [
        self::class,
        'entityBundleRouteTransactionName',
      ]);
    }
  }
  if ($route = $collection
    ->get('node.add')) {
    $route
      ->setDefault('_transaction_name_callback', [
      self::class,
      'nodeAddTransactionName',
    ]);
  }
}