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
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
YAML, which stands for YAML Ain't Markup Language, is a human-readable data serialization format that's been widely adopted in a variety of use cases in Drupal. Anyone wanting to write modules, or themes, for Drupal will need to understand YAML syntax. Even site builders are likely to encounter YAML at least in passing as YAML is the data-serialization format of choice for Drupal's configuration management system. Good thing it's pretty easy to learn even with the most basic of programming backgrounds.
This tutorial will look at the YAML data format and provide examples of how to write and read YAML. Starting with an introduction to the language's syntax and some of the strengths of YAML. Then looking at the difference between scalar data types like strings and integers, and collection data types like lists and associative arrays.
Since YAML in the Drupal world is read into PHP and ultimately becomes a PHP data structure that we can use in our own code we'll also look at how the YAML we write in a .yml file is represented in PHP data types. To do this we'll use the YAML Sandbox module that provides a handy textarea into which we can type YAML and have it parsed into PHP data structures.
Learning objectives
- Explain what YAML is and its strengths as a data serialization format
- Create scalar key/value pairs in YAML
- Create lists, and associative arrays using YAML collections
- Understand how the YAML you write is represented in PHP
Tips
- In Drupal, use the .yml extension and not .yaml
- Ensure your code editing application is configured to use spaces (preferably 2 spaces, as per Drupal coding standards), not the tab character when the TAB key is pressed. If you have tab characters in a YAML file within a Drupal environment, a fatal PHP error will be thrown and you'll see a White Screen of Death (WSOD).
- Copy and paste from an existing YAML file to ensure the formatting is correct, and edit from there.
Additional resources
- http://www.yaml.org
- YAML Sandbox module
- Find other tutorials and external resources related to YAML on our YAML topic page (Drupalize.Me)
PhpStorm IDE
CourseAn Integrated Development Environment (IDE) offers many code editing tools in one application, making your job as a developer much easier. In this introductory video from JetBrains, the creators of PhpStorm, you will see what an IDE has to offer.
Additional resources
Please note that this series covers PhpStorm versions 6 and 7 only.
For the latest documentation (including up-to-date videos), see JetBrains documentation.
In this tutorial you will get an overview of the PhpStorm IDE interface. We'll look at the areas in the main window, including the toolbar, navigation, editor, and tool regions.
Additional resources
Please note that this series covers PhpStorm versions 6 and 7 only.
For the latest documentation (including up-to-date videos), see JetBrains documentation.
This tutorial covers concepts you should understand when working with an IDE versus a text editor. We'll discuss how the concept of Projects works in PhpStorm, what Content Roots are, and how you can work with external Libraries.
Additional resources
Please note that this series covers PhpStorm versions 6 and 7 only.
For the latest documentation (including up-to-date videos), see JetBrains documentation.