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
In this lesson, learn how to use services and other useful objects like the service container in Symfony 3.
In this lesson, you'll learn how to find services you might want to use in the container by listing them.
In this lesson, you'll get a crash course in Twig. Covered here are the "say something" syntax, the "do something" syntax and for
loops. For broader coverage of Twig and the amazing things you can do with it, head over to the Twig Templating series.