This page is archived
We're keeping this page up as a courtesy to folks who may need to refer to old instructions. We don't plan to update this page.
PHP developers are excited that Drupal 8 has a new object-oriented framework with Symfony components. Are you ready to learn how to leverage these Symfony components in your Drupal 8 module? Then check out this new set of tutorials from our friends at KnpUniversity.
You'll learn some of the new Symfony concepts and tools used in Drupal 8 development, including routes, controllers, the services container, and events. You'll also learn to integrate new tools into your development workflow, including Drupal Console, Webprofiler (now part of Devel), Git, and Composer.
This series isn't just for Drupal 7 developers. If you're a PHP developer familiar with Symfony and you want to know how these components are used in the context of Drupal 8, this series is for you too.
Your trainer is Symfony documentation lead and Drupal community member, Ryan Weaver. He walks you through concepts and application in a custom module. By the end of this series you'll understand how to:
- Set up a new module with a route and a controller
- Get services out of the services container and into your module
- Listen for events and respond to them
- Utilize tools such as Drupal Console and Webprofiler in your development workflow
If you need a brush-up on object-oriented PHP and other key concepts, check out these prerequisite tutorials:
This tutorial is for PHP developers—including Drupal 7 developers—who want to get a local development environment up and running for Drupal 8 development work. In this tutorial, we will install Drupal 8, fire up the built-in PHP web server, set some variables in php.ini, initialize a Git repository, and discuss how Composer will impact what you commit to Git now and in the future. Finally, we'll walk through how to configure PhpStorm for Symfony development that plays nicely with Drupal 8 projects as well.
In this tutorial, we'll create a new module and create a route and controller for it. Remember
hook_menu is out and routes and controllers are in! If the YAML files in this lesson piqued your interest, check out our introduction to YAML tutorial to learn more.
Note: See Create an Info File for a Module for up-to-date instructions on info file requirements, which have changed since this video was recorded.
In this tutorial, we'll use an essential tool for Drupal 8 development: the Drupal Console. We'll take a look at how to list the commands available in Drupal Console and then use a Drupal Console command to clear the route cache.
Note: See the Drupal Console docs "Getting the project" page for the latest information on how to install Drupal Console. You will need to use Composer to install Drupal Console for each project.
In this tutorial, you will learn how to return a response through a controller using route wildcards. We'll walk through how the wildcard in the route was created and then how this wildcard gets passed as a parameter to the controller function, enabling you to display a value to the page based on the value in a particular URL path segment using Symfony's Response object.
Curious about the inner workings of the HTTP response? Dive into Symfony and HTTP Fundamentals, which takes you from HTTP fundamentals to how PHP handles HTTP requests and responses, and integrates what Symfony's tools bring to this flow from request to response.
In this tutorial, you'll learn how to turn on debugging tools through changing values in local.settings.php and then use these tools with the Drupal Console.
In this tutorial, we'll continue to look under the hood of Drupal 8, this time using a tool bundled with Devel called Webprofiler. You'll learn how to use the web debug toolbar and the profiler. You'll also learn how to reverse engineer a page to find out the names of the controllers responsible for output on that page.
Note: Webprofiler is now a separate project from Devel but still has it as a dependency.
Note: In order to get the Webprofiler timeline view working you need to add some configuration to your settings.php file. See the README.md file included with the Webprofiler module for more information on how to do this.
In this tutorial, we'll shift gears from routes and controllers to services. First off, you'll learn all about the Service Container, also known as the Dependency Injection Container. This is the basis for understanding these special objects called services and how you can leverage them in Drupal.
In this tutorial, you'll learn how to refactor the controller and create a service.
Now that we've created a service, let's configure it. In this tutorial, you'll learn how to register your new service. We'll also be using Drupal Console to ensure everything is working as it should.
Note: The Drupal Console command
container:debug is now
Note: Drupal Console is no longer maintained. There are other tools and methods for getting a list of services in the container. See the tutorial Discover and Use Existing Services to learn more.
In this tutorial, you will learn how to extend the
ControllerBase class in Drupal and get services out of the container.
In this tutorial, you'll see how Drupal's development.services.yml file can be used to configure services on a local environment. We'll use it to turn the cache off in our service during local development.
In this tutorial, you will learn how to create an event subscriber with dependency injection tags. You'll learn how to tell Drupal which event we want our code to listen for and what method to call when that event happens.
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
In this tutorial, we'll peel back the layers of the render array to find an event listener. We'll take a look at the core.services.yml file to unveil and solve the mystery of what's behind the render array.