O'Reilly logo

Drupal 8 Module Development by Daniel Sipos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required