function BreadcrumbPreprocessTest::preprocessBreadcrumb

Same name and namespace in other branches
  1. 11.x core/themes/default_admin/tests/src/Kernel/BreadcrumbPreprocessTest.php \Drupal\Tests\default_admin\Kernel\BreadcrumbPreprocessTest::preprocessBreadcrumb()

Runs the breadcrumb preprocessor against a route holding the entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity the route resolves to.

string $route_name: The route name to report as current.

Return value

array The preprocessed variables.

File

core/themes/default_admin/tests/src/Kernel/BreadcrumbPreprocessTest.php, line 129

Class

BreadcrumbPreprocessTest
Tests breadcrumb preprocessing for entities.

Namespace

Drupal\Tests\default_admin\Kernel

Code

protected function preprocessBreadcrumb($entity, string $route_name) : array {
  $entity_type_id = $entity->getEntityTypeId();
  $route = new Route('/' . $entity_type_id . '/{' . $entity_type_id . '}/edit');
  $route->setOption('parameters', [
    $entity_type_id => [
      'type' => 'entity:' . $entity_type_id,
    ],
  ]);
  $route_match = new RouteMatch($route_name, $route, [
    $entity_type_id => $entity,
  ]);
  $hooks = new PreprocessHooks($this->container
    ->get('theme.manager'), $this->container
    ->get('request_stack'), $route_match, $this->container
    ->get('config.factory'), $this->container
    ->get('current_user'), $this->container
    ->get('entity_type.manager'), $this->container
    ->get('entity_type.bundle.info'), $this->container
    ->get('plugin.manager.block'), $this->container
    ->get('renderer'), $this->container
    ->get('module_handler'));
  $variables = [
    'breadcrumb' => [
      [
        'text' => 'Home',
        'url' => '/',
      ],
    ],
  ];
  $hooks->preprocessBreadcrumb($variables);
  return $variables;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.