Drupal 9 entity.repository load entity by UUID

To load an entity by UUID in Drupal 9 using the entity repository, you can use the following code snippet:

use Drupal\Core\Entity\EntityRepositoryInterface;

// Inject the entity repository service.
public function __construct(EntityRepositoryInterface $entityRepository) {
  $this->entityRepository = $entityRepository;
}

// Load the entity by UUID.
$uuid = 'your_uuid_here';
$entity = $this->entityRepository->loadEntityByUuid('entity_type_id', $uuid);

Replace 'your_uuid_here' with the actual UUID of the entity you want to load, and 'entity_type_id' with the ID of the entity type you are working with (e.g., 'node' for nodes, 'user' for users, etc.).

This code assumes that you have properly injected the EntityRepositoryInterface service into your class constructor or retrieved it using dependency injection.

Make sure to adjust the code to fit your specific use case and requirements.