Utilize Event Arguments and Request Objects

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:08
    We now know that
  • 0:10
    when you listen to this event,
  • 0:11
    it passes you an event object
  • 0:13
    called GetResponseEvent.
  • 0:16
    Type hint the argument
  • 0:17
    to enjoy autocompletion.
  • 0:19
    This event object has a GetRequest method.
  • 0:22
    Use that to set a new request variable.
  • 0:25
    This is Drupal's
  • 0:26
    and Symfony's request object.
  • 0:08
    Nós sabemos que
  • 0:10
    quando você escuta esse evento,
  • 0:11
    ele passa para você um objeto de evento
  • 0:13
    chamado GetResponseEvent.
  • 0:16
    Defina o tipo do argumento
  • 0:17
    para se aproveitar do autocompletar.
  • 0:19
    Esse objeto de evento tem um método GetRequest.
  • 0:22
    Use isso para definir uma nova variável de requisição.
  • 0:25
    Esse é o objeto de requisição
  • 0:26
    do Drupal e do Symfony,

Utilize Event Arguments and Request Objects

Loading...

In this tutorial you'll learn how to make use of the event object that are passed to you and the methods that come with it. You'll also learn how to use dependency injection to add a logger for our class and add this argument to our services YAML file.

Note: Drupal 9 now requires Symfony 4.4. The class mentioned at 0:15, \Symfony\Component\HttpKernel\Event\GetResponseEvent, is deprecated. Use \Symfony\Component\HttpKernel\Event\RequestEvent instead.