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.
This tutorial breaks down the editor actions for PhpStorm. We take a look making mistakes in our code and how to see the errors and warnings that PhpStorm provides. We'll also work with the editor tabs, favorites, and bookmarks.
Corrections
At 2:22, the keyboard shortcut on Mac OS X should use the letter O, not N. Here are the correct commands and their alternatives for Mac OS X:
Navigate to Class by pressing Ctrl+N (command+O on Mac OS X)
Navigate to File by pressing Ctrl+Shift+N (shift+command+O on Mac OS X)
Navigate to Symbol by pressing Ctrl+Shift+Alt+N (option+command+O on Mac OS X)
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 PhpStorm tutorial we'll start working with some code in order to learn how to use code templates, and see the various ways that you can work with auto-completion and code generation options, which will save you a lot of time when coding. You'll also be able to see how the IDE provides you with solutions to fix errors in your code.
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.
All of your work in PhpStorm will happen within a project. In this tutorial, we'll look at how to create a new empty project, or start one from existing files. We walk through the different types of projects you can start with, including Composer, and HTML templates, like Foundation and Twitter Bootstrap. We also take a look at setting up a project with remote servers.
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.
PhpStorm can save you a lot of time by generating common code for you, including classes, constructors, getters, setters, and PHP doc blocks. We'll also look at common editor generation of things like loops.
See the written version of this tutorial for keyboard shortcuts.
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 we'll explain what PSR-0 and PSR-4 namespacing is. Then we'll look at how to configure namespacing in PhpStorm 8. Drupal 8 is using PSR-4, so this is a really great tool to have when working in Drupal 8 projects.
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.
Many languages use the concept of namespaces. PHP uses it to group together classes. This tutorial shows you how to work efficiently with namespaces in PhpStorm.
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.
Composer is a great PHP package manager, and in this tutorial you'll see how to work with Composer from within the PhpStorm IDE. To learn more about Composer, watch The Wonderful World of Composer video tutorial.
Additional resources
Composer project
Packagist.org
Please note that this series covers PhpStorm versions 6 and 7 only.
For the latest documentation (including up-to-date videos), see JetBrains documentation.