Commit 7e80ae23 authored by anon's avatar anon Committed by anon

Issue #2766593 by anon: Make the EntityMatcherDeriver more strict

parent 577c096f
......@@ -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();
......
<?php
namespace Drupal\Tests\linkit\Kernel;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\Routing\Route;
/**
* Tests the entity matcher deriver.
*
* @group linkit
*/
class EntityMatcherDeriverTest extends LinkitKernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['block', 'block_content', 'node', 'field'];
/**
* The matcher manager.
*
* @var \Drupal\linkit\MatcherManager
*/
protected $manager;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment