Skip to Main Content
Close Menu

Updating deprecated entityManager() calls in Drupal 8


This covers only the most common use cases.







A little more information

If you are using less common methods

EntityManager was split into 11 new services. Based on which methods you were calling on the service, you will need to load a different service.

See for the list of methods supported by each service.






If you are replacing usage in a controller class that extends ControllerBase

ControllerBase now injects EntityTypeManager. If you are using methods used with that new service, you can do a simple replacement.





More complex updates

If you would like to use dependency injection and are not using methods available in EntityTypeManager within a controller that extends ControllerBase, you will need to inject the service yourself.

Unfortunately, dependency injection patterns for services, controllers, and plugins (example: block plugin) are different. See for some examples of how dependency injection looks for these.

More examples

We have a set of examples as part of the Drupal Rector rector_examples module. See

Automating updates with Drupal Rector

Drupal Rector is an open source tool built using Rector which can help automate this deprecation as well as other common deprecations.

For more information, see

What is covered by the rector

Drupal Rector currently replaces static calls to \Drupal::entityManager() as shown above.

If a class extends the ControllerBase class and is using the EntityTypeManager service, the dependency injection pattern will be used. This looks like $this->entityTypeManager().

Improvement opportunities

Drupal Rector does not inject services into classes that don’t already have the services injected by extending ControllerBase.

Drupal Rector does not handle the complex use case when a service other than EntityTypeManager is needed and the method does not directly call the service. This most often occurs when a variable is used to store the service and then called on separate statements. It’s possible that several services would need to be called going forward.

Deprecation background

The EntityManager service was originally narrow in scope and used to discover entity types. This functionality grew and it was decided to split the service into 11 services. To support backwards compatibility, the EntityManager service was left in place, but serves as a wrapper around those new services.

The EntityManager was deprecated in 8.0.0, but was used heavily in Drupal 8. A lot of this use may have been because of its availability as part of controllers that extended ControllerBase and also because of the similarity in naming between EntityManager and EntityTypeManager.


The Drupal change record for this deprecation is available at  

Credits and thank yous

Thank you to Dan Montgomery for leading Drupal Rector development to support this deprecation.

Thank you to for sponsoring this development.

Let’s work together.

Have an exceptional idea? Let's talk and see how we can help.
Contact Us