function EntityViewAlterTest::testContextualLinksRemoved
Tests that contextual links are removed when rendering Layout Builder.
File
- 
              core/modules/ layout_builder/ tests/ src/ Kernel/ EntityViewAlterTest.php, line 47 
Class
- EntityViewAlterTest
- @covers layout_builder_entity_view_alter[[api-linebreak]]
Namespace
Drupal\Tests\layout_builder\KernelCode
public function testContextualLinksRemoved() : void {
  $display = LayoutBuilderEntityViewDisplay::load('entity_test.bundle_with_extra_fields.default');
  $entity = EntityTest::create();
  $build = [
    '#contextual_links' => [
      'entity.node.canonical',
    ],
  ];
  // Create a fake request that starts with layout_builder.
  $request = Request::create('<front>');
  $request->attributes
    ->set(RouteObjectInterface::ROUTE_NAME, 'layout_builder.test');
  $request->attributes
    ->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/'));
  $request->setSession(new Session(new MockArraySessionStorage()));
  \Drupal::requestStack()->push($request);
  // Assert the contextual links are removed.
  layout_builder_entity_view_alter($build, $entity, $display);
  $this->assertArrayNotHasKey('#contextual_links', $build);
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
