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

Service approach

The service approach involves creating a tagged service and referencing that in the route definition as a requirement. There are a number of advantages to this method compared to the one we've just seen:

  • Allows you to encapsulate complex access logic in its own class
  • Allows you to inject dependencies and make use of them in calculating the access
  • Allows you to reuse the access checker on multiple routes

So, let's take a look at how we can implement this for our Hello World route. We will replace the preceding approach, but keep the goal of denying access to editors. However, to increase a bit, complexity, editors will be allowed if the Hello World salutation has not been overridden via the configuration form. If you recall, ...

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