Call to undefined method Drupal::EntityManager()

When upgrading to drupal 9 you can encounter the following:

 Call to undefined method Drupal::EntityManager()

Change your code from:

$entity = \Drupal::EntityManager()->loadEntityByUuid($entity_type, $uuid);

to

$entity = \Drupal::service('entity.repository')->loadEntityByUuid($entity_type, $uuid);

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!