Logging for Hello World

Now that we have all the tools at our disposal, and more importantly, understand how logging works in Drupal 8, let's add some logging to our module.

There is one place where we can log an action that may prove helpful. Let's log an info message when an administrator changes the greeting message via the form we wrote. This should naturally happen in the submit handler of SalutationConfigurationForm.

If you remember my rant in the previous chapter, there is no way we should use a service statically if we can instead inject it, and we can easily inject services into our form. So, let's do this now.

First of all, FormBase already implements ContainerInjectionInterface, so we don't need to implement it in our class, as ...

Get Drupal 8 Module Development - Second Edition 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.