From 9382d0a32d0f3058276cd4e601556658905fb608 Mon Sep 17 00:00:00 2001
From: Claudiu Cristea <7931-claudiucristea@users.noreply.drupalcode.org>
Date: Fri, 26 Apr 2024 08:56:12 +0000
Subject: [PATCH] Don't thorow needless exception

---
 src/ReferenceUpgrader.php | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/src/ReferenceUpgrader.php b/src/ReferenceUpgrader.php
index e533d7e2..9205d2d7 100644
--- a/src/ReferenceUpgrader.php
+++ b/src/ReferenceUpgrader.php
@@ -29,15 +29,9 @@ final class ReferenceUpgrader {
    * Registers entities.
    */
   public function registerEntity(EntityInterface $entity) {
-    $entityId = $entity->id() ?? $this->throwNeedsId();
-    $this->entities[$entity->getEntityTypeId()][$entityId] = $entity;
-  }
-
-  /**
-   * Throws exceptions on trying to register entities without id.
-   */
-  private function throwNeedsId() {
-    throw new \RuntimeException("Can only register entity with ID.");
+    if ($entityId = $entity->id()) {
+      $this->entities[$entity->getEntityTypeId()][$entityId] = $entity;
+    }
   }
 
   /**
-- 
GitLab