diff --git a/src/Plugin/Derivative/EntityMatcherDeriver.php b/src/Plugin/Derivative/EntityMatcherDeriver.php index afcdbbb8d7099a68718b8ecce563144516c09e29..764d63c6179d1d1c9df48dc9d5131d747039daf8 100644 --- a/src/Plugin/Derivative/EntityMatcherDeriver.php +++ b/src/Plugin/Derivative/EntityMatcherDeriver.php @@ -45,9 +45,12 @@ class EntityMatcherDeriver extends DeriverBase implements ContainerDeriverInterf */ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { - $has_canonical = $entity_type->hasLinkTemplate('canonical'); + $canonical = $entity_type->getLinkTemplate('canonical'); + $edit_form = $entity_type->getLinkTemplate('edit-form'); - if ($has_canonical) { + // Only entities that has a distinct canonical URI that is not the same + // as the edit-form URI will be derived. + if ($canonical && ($canonical !== $edit_form)) { $this->derivatives[$entity_type_id] = $base_plugin_definition; $this->derivatives[$entity_type_id]['id'] = $base_plugin_definition['id'] . ':' . $entity_type_id; $this->derivatives[$entity_type_id]['label'] = $entity_type->getLabel(); diff --git a/tests/src/Kernel/EntityMatcherDeriverTest.php b/tests/src/Kernel/EntityMatcherDeriverTest.php new file mode 100644 index 0000000000000000000000000000000000000000..fc921c02c0a0be3781c224eb09a7feb9e6f26227 --- /dev/null +++ b/tests/src/Kernel/EntityMatcherDeriverTest.php @@ -0,0 +1,55 @@ +installConfig(['block_content']); + $this->installEntitySchema('block_content'); + + $this->installEntitySchema('node'); + $this->installConfig(['field', 'node']); + + $this->manager = $this->container->get('plugin.manager.linkit.matcher'); + } + + /** + * Tests the deriver. + */ + public function testDeriver() { + $definition = $this->manager->getDefinition('entity:block_content', FALSE); + $this->assertNull($definition); + $definition = $this->manager->getDefinition('entity:node', FALSE); + $this->assertNotNull($definition); + } + +}