diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index a4fcf66..ac2fc14 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -547,6 +547,10 @@ public function hasLinkTemplate($key) { * {@inheritdoc} */ public function setLinkTemplate($key, $path) { + if ($path[0] !== '/') { + throw new \InvalidArgumentException('Link templates takes path, which have to start with a leading slash.'); + } + $this->links[$key] = $path; return $this; } diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 6cad751..4cd49f8 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -96,9 +96,9 @@ function field_ui_entity_type_build(array &$entity_types) { // This allows us to not require route information inside this hook, which // otherwise could result in circular dependencies. $entity_type - ->setLinkTemplate('field_ui-fields', "admin/{$entity_type->id()}/fields") - ->setLinkTemplate('field_ui-form-display', "admin/{$entity_type->id()}/fields-form-display") - ->setLinkTemplate('field_ui-display', "admin/{$entity_type->id()}/fields-display"); + ->setLinkTemplate('field_ui-fields', "/admin/{$entity_type->id()}/fields") + ->setLinkTemplate('field_ui-form-display', "/admin/{$entity_type->id()}/fields-form-display") + ->setLinkTemplate('field_ui-display', "/admin/{$entity_type->id()}/fields-display"); } } } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php index c6d70ce..c4ae0b6 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php @@ -241,4 +241,14 @@ protected function getTestHandlerClass() { return get_class($this->getMockForAbstractClass('Drupal\Core\Entity\EntityHandlerBase')); } + /** + * @covers ::setLinkTemplate + * + * @expectedException \InvalidArgumentException + */ + public function testSetLinkTemplateWithInvalidPath() { + $entity_type = $this->setUpEntityType(['id' => $this->randomMachineName()]); + $entity_type->setLinkTemplate('test', 'invalid-path'); + } + }