diff -u b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php --- b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php +++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php @@ -363,9 +363,7 @@ // Disallow references to the referencing entity. $entity = $this->configuration['entity'] ? $this->configuration['entity'] : NULL; if ($entity instanceof EntityInterface) { - // To maintain backwards compatibility: if the setting is not set, then - // allow referencing self. - $allow_self_reference = isset($configuration['handler_settings']['allow_self_reference']) ? !empty($configuration['handler_settings']['allow_self_reference']) : TRUE; + $allow_self_reference = !empty($configuration['handler_settings']['allow_self_reference']); if (!$allow_self_reference) { // Referencing entity must be the same entity type as the query. if ($entity->getEntityTypeId() == $entity_type->id()) { diff -u b/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php b/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php --- b/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php +++ b/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php @@ -92,7 +92,7 @@ ->setSetting('handler_settings', $handler_settings) ->save(); - $entity = EntityTestNoLabel::create(['name' => $this->randomMachineName()]); + $entity = EntityTest::create(['name' => $this->randomMachineName()]); $entity->save(); $other = EntityTest::create(['name' => $this->randomMachineName()]); $other->save(); @@ -117,10 +117,6 @@ */ public function providerAllowSelfReference() { return [ - 'when setting is omitted, referencing entity is referencable' => [ - NULL, - TRUE, - ], 'when setting is true, referencing entity is referencable' => [ TRUE, TRUE, @@ -140,7 +136,7 @@ */ public function testPreventSelfReferenceDifferentEntityType() { $field_name = 'field_test'; - $this->createEntityReferenceField('entity_test', 'entity_test', $field_name, 'Test entity reference', 'entity_test'); + $this->createEntityReferenceField('entity_test', 'entity_test', $field_name, 'Test entity reference', 'entity_test_no_label'); $field_config = FieldConfig::loadByName('entity_test', 'entity_test', $field_name); $handler_settings = $field_config->getSetting('handler_settings'); $handler_settings['allow_self_reference'] = FALSE; @@ -148,9 +144,9 @@ ->setSetting('handler_settings', $handler_settings) ->save(); - $entity = EntityTestNoLabel::create(['name' => $this->randomMachineName()]); + $entity = EntityTest::create(['name' => $this->randomMachineName()]); $entity->save(); - $other = EntityTest::create(['name' => $this->randomMachineName()]); + $other = EntityTestNoLabel::create(['name' => $this->randomMachineName()]); $other->save(); // The entity type doesn't matter, so long as it is a different type to the @@ -163,7 +159,7 @@ ->get('plugin.manager.entity_reference_selection') ->getSelectionHandler($field_config, $entity); - $referenceable = $handler->getReferenceableEntities()['entity_test']; + $referenceable = $handler->getReferenceableEntities()['entity_test_no_label']; $this->assertArrayHasKey($entity->id(), $referenceable, 'Can reference entity even though the IDs are the same.'); }