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

Checking the user credentials

You can easily check whether a given user should access a certain resource as long as you have that user account at hand. Here, you can encounter two scenarios:

  • You want to interrogate the current user
  • You want to interrogate a given user, not necessarily the current one

As we saw in Chapter 2, Creating Your First Module, the current user is represented by a service, which implements the AccountProxyInterface interface. This service can be accessed by the current_user key or statically with this shorthand:

/** @var AccountProxyInterface $accountProxy */
$accountProxy = \Drupal::currentUser();

From this account proxy, we can request the AccountInterface, which represents the actual logged-in user account (the ...

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