Getting Started - Background & Prerequisites
Drupal leverages a number of advanced PHP language features and sophisticated 3rd party libraries in order to present external developers with the most advanced API of any CMS available. While experienced Drupal 7 developers may see some significant changes, much of the basic structure will remain familiar.
If any of the material presented while going through the D8 module developer's walk-through is new to you, then the material below may help. However, a comprehensive knowledge is not necessary to proceed to the D8 module walkthrough.
Object Oriented Programming
OOP, while initially daunting, is now well established as a best practice.
For a general overview of PHP best practices, read through phptherightway.com. Drupal doesn't make use of all the different tools and techniques documented there but it does serve as a great introduction to PHP and the language's many features.
Brush up on your OOP knowledge by reading the official PHP documentation on Classes and Objects as well as some of these other good primers:
- PHP OOP in Full Effect
- Object-oriented programming (on Wikipedia)
- Object-Oriented PHP for Beginners (at tuts+)
- Object Oriented Concepts (at tutorialspoint.com)
- Object Oriented Programming in PHP (at youtube.com)
- Foundations of Programming: Object Oriented Design (at lynda.com)
- Must know 12 PHP OOP concepts
- OOP Track on SymfonyCasts (formerly KNP university)
Drupal 8 also makes use of some common design patterns and you'll want to make sure you have a basic understanding of these:
- The Factory Pattern, and Late static bindings
- Software design pattern (on Wikipedia)
- Foundations of Programming: Design Patterns (at lynda.com)
- @todo: add more links to documentation about the patterns we use ...
PHP Namespaces
If you're unfamiliar with the concept of namespacing in PHP, try some of these articles:
- How to use PHP namespaces.
- PHP: Namespaces
- a video on PHP namespaces.
- PHP Namespaces Explained (by Dayle Rees)
- Namespacing in PHP (at tuts+)
In most cases, the Drupal code is namespaced based on the module that code belongs to.
Example: namespace for the block.module
namespace Drupal\block;
@todo: explain why sometimes it's Drupal\ and sometimes it's Drupal\\[Controller|Form|Plugin|etc.] and how I should know which to use ...
Read more about the Drupal namespace standards. More on PSR-4 usage in Drupal here. Correctly configured coding software should be able to pick up on PHP namespaces and provide help and autocompletions.
Dependency Injection
Although dependency injection is really just another OOP design pattern, we call it out here because Drupal 8 makes heavy use of the concept and it is important to have a baseline understanding in order to access and make use of many of the core APIs.
Read up on dependency injection on PHP the right way, as well as the additional articles linked on that page. Especially this article because Drupal makes heavy use of the Symfony service container referenced.
See also:
Symfony
Symfony is a PHP framework that Drupal borrows from in order to reduce code duplication across various PHP projects. Much of the code that Drupal 8 uses to handle routing, sessions and the services container, amongst other things, is borrowed from Symfony 2 (and as Drupal 8 developed, moved into Symfony 3). If you want to know more about why this decision was made, check out this presentation by core-committer alexpott for some background.
Check out the Symfony book and brush up on your Symfony knowledge. While not all of it is required to understand Drupal, knowing how Symfony works will make you both a better Drupal developer and a better PHP developer. You might also be interested in the Symfony Glossary.
Check out core/composer.lock to see the Symfony libraries. As of Drupal 8.6.15, these are the Symfony PHP and closely related libraries:
...
"symfony/class-loader": "~3.4.0",
"symfony/console": "~3.4.0",
"symfony/dependency-injection": "~3.4.26",
"symfony/event-dispatcher": "~3.4.0",
"symfony/http-foundation": "~3.4.26",
"symfony/http-kernel": "~3.4.14",
"symfony/routing": "~3.4.0",
"symfony/serializer": "~3.4.0",
"symfony/translation": "~3.4.0",
"symfony/validator": "~3.4.0",
"symfony/process": "~3.4.0",
"symfony/polyfill-iconv": "^1.0",
"symfony/yaml": "~3.4.5",
"twig/twig": "^1.38.2",
"doctrine/common": "^2.5",
"doctrine/annotations": "^1.2",
...
Annotations
Drupal 8 makes use of PHP annotations – @docblock comments added to your code using a special syntax – for plugin discovery and to provide additional context/meta-data for code that's being executed. Annotations are read using the Doctrine annotation parser (v.1.6.) then turned into information that Drupal can use to better understand what your code is doing.
Read more about the use of annotations for plugin discovery.
See a list of all the different annotation types in Drupal 8.
See also: PHPDoc (on Wikipedia)
Plugins
Plugins provide small pieces of functionality in such a way that they can be easily swapped out for another plugin. Plugins that perform similar functionality are of the same plugin type. For example, 'Field widget' is a plugin type, and each different field widget (eg. text field, textarea, date, etc.) is implemented with a plugin.
Read more about the Plugin API in Drupal 8.
Services
In Drupal 8 speak, a service is any object managed by the services container. The concept of services was introduced to decouple reusable functionality and makes these services pluggable and replaceable by registering them with a service container of dependency injection, which they heavily relate to.
- See also: Service Container For Drupal Geeks (on YouTube)
Other resources
Below is a list of additional resources to help ensure that you hit the ground running with Drupal 8.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion