Injecting services into Entity handlers

One of the powers of using the access handler is that we can make it aware of the service container and inject whatever services we might need to determine access. However, it's not immediately clear how you can do this, so we'll break it down here.

The first thing we will need is to have our access handler implement the EntityHandlerInterface. Note that this applies in the same way to the other types of handlers, not just access related. This interface has one method, which will receive the container and the entity type definition--createInstance().

Knowing this, the rest is very similar to how we injected services into Controllers and Forms using the create() method, which only takes the container ...

Get Drupal 8 Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.