summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoranon2016-07-14 23:47:49 +0200
committerEmil Stjerneman2016-07-14 23:47:49 +0200
commit7e80ae23954f36c8f45952453c76886a8b2d96e7 (patch)
tree485532024db77c008fa901712b934c7509fd538f
parent577c096ff3503c395c7d99f6a72e191ed1384990 (diff)
Issue #2766593 by anon: Make the EntityMatcherDeriver more strict8.x-5.0-beta2
-rw-r--r--src/Plugin/Derivative/EntityMatcherDeriver.php7
-rw-r--r--tests/src/Kernel/EntityMatcherDeriverTest.php55
2 files changed, 60 insertions, 2 deletions
diff --git a/src/Plugin/Derivative/EntityMatcherDeriver.php b/src/Plugin/Derivative/EntityMatcherDeriver.php
index afcdbbb..764d63c 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 0000000..fc921c0
--- /dev/null
+++ b/tests/src/Kernel/EntityMatcherDeriverTest.php
@@ -0,0 +1,55 @@
+<?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);
+ }
+
+}