diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 1c44234a741a56ca90762658e01467db899bfbdd..1ab6691ecc3431257343ecfbb894885c3340b1b6 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 b0a6156a2545c1da1de26a65d9bdfb5f3c017e8a..230daf7e72f27f1790f5939ae2287480ccfa2006 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 0000000000000000000000000000000000000000..71bc9b5365426a2a52004246254ae0532c74e716 --- /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 ccbc41473f999ae654f16e7ef1274ffcd6826952..aa93e71b0503419f281c95590b1b6c9f5dc4bda6 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) {