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.
Additional resources
Drupal Console — Download and Documentation
Drupal Console: Getting the Project
Tutorial: Drupal Console (Drupalize.Me)
Composer
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.
We're assuming you have the Drupal Console up and running (which we set up in the previous tutorial). The drupal
command calls Drupal Console.
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.
Additional resources
Symfony and HTTP Fundamentals — Symfony Documentation
Http Foundation Response Object — Symfony Documentation
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.
We're assuming you have the Drupal Console up and running (which we set up in the previous tutorial). The drupal
command calls Drupal Console.
Additional resources
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.
Additional resources
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.
Additional resources
In this tutorial, you'll learn how to refactor the controller and create a service.
Additional resources
Dependency Injection and the Art of Services and Containers — Drupalize.Me
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 debug:container
.
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.
Additional resources
Discover and Use Existing Services
Dependency Injection and the Art of Services and Containers — Drupalize.Me
An Introduction to YAML — Drupalize.Me
In this tutorial, you will learn how to extend the ControllerBase
class in Drupal and get services out of the container.
Additional resources
Injecting services in your D8 plugins (lullabot.com)
abstract class ControllerBase — api.drupal.org
PHP Service Container — Drupalize.Me
In this tutorial, we'll explore some of the helper functions in ControllerBase
. We'll discover the magic behind these shortcut functions is services!
Additional resources
abstract class ControllerBase — api.drupal.org
PHP Service Container — Drupalize.Me
In this tutorial, you'll learn how to get a service that's in another service by using the special constructor method.
Additional resources
In this tutorial, we'll inject some configuration into our constructor class and introduce parameters by way of our services YAML file.
Additional resources
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.
Additional resources
In this tutorial, you'll learn all about events versus hooks in Drupal 8 and we'll introduce the concept of event listeners.
Additional resources
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.
Additional resources
An Introduction to YAML — Drupalize.Me
Introduction to Interfaces — Drupalize.Me
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.
Additional resources
Introduction to Interfaces — Drupalize.Me
An Introduction to YAML — Drupalize.Me
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.
Additional resources
In this lesson, you will learn how to get a Symfony 3 project started. First download Symfony and then follow along with this video tutorial.
Additional resources
Learn how to set up the IDE PhpStorm for Symfony 3 development. In this lesson, you'll install the Symfony plugin. You'll also want to install the PHP Annotations plugin in the same manner. Finally, you'll initialize a new Git repository on your system.
Additional resources
In this lesson you'll build your first page in Symfony 3. Be sure to download the code below so that you can follow along.
Tip: You should also find and install the PHP Annotations plugin. That will give you the awesome annotations auto-completion that you'll see in the video.
Additional resources
PHP Namespaces in 120 Seconds
PHP Namespaces Support in PhpStorm
PHP Annotations plugin for PhpStorm
In this lesson, learn how to make use of routing wildcards in a Symfony 3 app.
Additional resources
Be careful when rendering direct user input (like we show here)! It introduces a security issue called XSS. Read more about XSS here