Issue #3012172 by acbramley: EntityViewBuilder::addContextualLinks assumes an entity's canonical rel is routed/internal

(cherry picked from commit caa4845430)
merge-requests/803/head
catch 2021-06-11 11:40:57 +01:00
parent ae21ac5cf8
commit af362ba8a6
2 changed files with 15 additions and 1 deletions

View File

@ -362,7 +362,7 @@ class EntityViewBuilder extends EntityHandlerBase implements EntityHandlerInterf
$rel = 'revision';
$key .= '_revision';
}
if ($entity->hasLinkTemplate($rel)) {
if ($entity->hasLinkTemplate($rel) && $entity->toUrl($rel)->isRouted()) {
$build['#contextual_links'][$key] = [
'route_parameters' => $entity->toUrl($rel)->getRouteParameters(),
];

View File

@ -343,4 +343,18 @@ class EntityViewBuilderTest extends EntityKernelTestBase {
$this->assertArrayNotHasKey('#theme', $build);
}
/**
* Tests an entity type with an external canonical rel.
*/
public function testExternalEntity() {
$this->installEntitySchema('entity_test_external');
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container->get('renderer');
$entity_test = $this->createTestEntity('entity_test_external');
$entity_test->save();
$view = $this->container->get('entity_type.manager')->getViewBuilder('entity_test_external')->view($entity_test);
$renderer->renderRoot($view);
$this->assertArrayNotHasKey('#contextual_links', $view);
}
}