From 2da508579c6a30f8e51b1cbeaeea45f88cce4034 Mon Sep 17 00:00:00 2001
From: Dries <dries@buytaert.net>
Date: Wed, 18 Jun 2014 22:10:59 +0200
Subject: [PATCH] Issue #2285349 by olli: Fixed Fatal error: Call to a member
 function getType() on a non-object in comment.module on line 951.

---
 core/modules/comment/comment.module           |  3 ++
 .../comment/src/Tests/CommentNonNodeTest.php  |  9 ++++++
 .../entity_test/src/Entity/EntityTestNoId.php | 30 +++++++++++++++++++
 .../src/Routing/EntityTestRoutes.php          |  1 +
 4 files changed, 43 insertions(+)
 create mode 100644 core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoId.php

diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 1c44234a741a..1ab6691ecc34 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -863,6 +863,9 @@ function comment_entity_predelete(EntityInterface $entity) {
 function _comment_entity_uses_integer_id($entity_type_id) {
   $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
   $entity_type_id_key = $entity_type->getKey('id');
+  if ($entity_type_id_key === FALSE) {
+    return FALSE;
+  }
   $field_definitions = \Drupal::entityManager()->getBaseFieldDefinitions($entity_type->id());
   $entity_type_id_definition = $field_definitions[$entity_type_id_key];
   return $entity_type_id_definition->getType() === 'integer';
diff --git a/core/modules/comment/src/Tests/CommentNonNodeTest.php b/core/modules/comment/src/Tests/CommentNonNodeTest.php
index b0a6156a2545..230daf7e72f2 100644
--- a/core/modules/comment/src/Tests/CommentNonNodeTest.php
+++ b/core/modules/comment/src/Tests/CommentNonNodeTest.php
@@ -433,6 +433,15 @@ public function testsStringIdEntities() {
     $this->drupalLogin($limited_user);
     // Visit the Field UI overview.
     $this->drupalGet('entity_test_string_id/structure/entity_test/fields');
+    // Ensure field isn't shown for empty IDs.
+    $this->assertNoOption('edit-fields-add-new-field-type', 'comment');
+
+    entity_test_create_bundle('entity_test', 'Entity Test', 'entity_test_no_id');
+    $this->drupalLogin($this->drupalCreateUser(array(
+      'administer entity_test_no_id fields',
+    )));
+    // Visit the Field UI overview.
+    $this->drupalGet('entity_test_no_id/structure/entity_test/fields');
     // Ensure field isn't shown for string ids.
     $this->assertNoOption('edit-fields-add-new-field-type', 'comment');
   }
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoId.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoId.php
new file mode 100644
index 000000000000..71bc9b536542
--- /dev/null
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoId.php
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\entity_test\Entity\EntityTestNoId.
+ */
+
+namespace Drupal\entity_test\Entity;
+
+/**
+ * Test entity class.
+ *
+ * @ContentEntityType(
+ *   id = "entity_test_no_id",
+ *   label = @Translation("Entity Test without id"),
+ *   controllers = {
+ *     "storage" = "Drupal\Core\Entity\ContentEntityNullStorage",
+ *   },
+ *   fieldable = TRUE,
+ *   entity_keys = {
+ *     "bundle" = "type",
+ *   },
+ *   links = {
+ *     "admin-form" = "entity_test.admin_entity_test_no_id"
+ *   }
+ * )
+ */
+class EntityTestNoId extends EntityTest {
+
+}
diff --git a/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php b/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php
index ccbc41473f99..aa93e71b0503 100644
--- a/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php
+++ b/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php
@@ -23,6 +23,7 @@ class EntityTestRoutes {
   public function routes() {
     $types = entity_test_entity_types();
     $types[] = 'entity_test_string_id';
+    $types[] = 'entity_test_no_id';
 
     $routes = array();
     foreach ($types as $entity_type) {
-- 
GitLab