entityTypeManager->getStorage($entity->getEntityTypeId()); $controller->resetCache([$entity->id()]); return $controller->load($entity->id()); } /** * Generates a random ID avoiding collisions. * * @param bool $string * (optional) Whether the id should have string type. Defaults to FALSE. * * @return int|string * The entity identifier. */ protected function generateRandomEntityId(bool $string = FALSE): int|string { srand(time()); do { // 0x7FFFFFFF is the maximum allowed value for integers that works for all // Drupal supported databases and is known to work for other databases // like SQL Server 2014 and Oracle 10 too. $id = $string ? $this->randomMachineName() : mt_rand(1, 0x7FFFFFFF); } while (isset($this->generatedIds[$id])); $this->generatedIds[$id] = $id; return $id; } }