How forms are structured in Drupal 8

Description

In the same way that block code was consolidated into a single class in Drupal 8, forms also are encapsulated into a single form class. Here we look at a simple form example.

Transcript

Okay. So we are in ImageToolkitForm. That's in the folder, Form, under source and system, okay? And if we look at this full file -- I'm going to scroll up to the top -- it says this class extends from ConfigFormBase.

So that sounds about right for what we are trying to go for. If we look at the full signature -- I'm going to click on Structure just so we can see -- we have the constructor, we have create, getFormid, buildForm, and submitForm. What you might notice here if you haven't played with Drupal 8 at all yet is that this is much more consolidated than what we had in Drupal 7.

In Drupal 7, when you wanted to create a form, you would create the form function, you would create a submit function that had a function name that was extended from the name of the form, and then a validate function that was also extended from the name of the form. So you would have a few vaguely related functions that all tied in to this one form. Now, instead of that, we have one class.

This collection will not only prepare you to work with and understand Drupal 8 under the hood, it will increase your skills and relevance as a developer. We cover Object Oriented Programming (OOP), how to use Composer, what the Symfony framework is and how to use its various components, plus lots, lots more. For developers really wanting to modernize their skill set, this is a great place to start.

Before watching this series, you will need a web environment with Drupal 8 installed. Follow the videos in the Setting Up a Web Environment With Drupal to set up a web environment. In the series, we use a couple different versions of Drupal 8 and provide instructions for installing each one so you can follow along with the series exactly. You can also use the latest version of Drupal 8, but there will be some slight differences between what you see in the videos and how you would put what you see into practice, but working through those differences can be excellent for learning.

Some of the key points we'll be covering include:

How to build basic module scaffolding in Drupal 8

How Object-Oriented Programming (OOP) works and how to apply what you learn to coding in Drupal 8

How to work with Symfony components included in Drupal 8

How to use Composer to keep track of code dependencies and leverage a huge library of PHP components

Who this collection is for

This collection is mostly for Drupal developers who want to upgrade their techniques to work with Drupal 8. Because many of these techniques are applicable to PHP coding in general, it can also be useful if you simply want to develop your PHP skills and wrap your mind around object-oriented programming.

Prerequisites

You will get the most out of this collection if you are comfortable with procedural coding in PHP. We will make references to how code works in Drupal 7, so it will be helpful if you have some Drupal coding experience in particular.

It looks like there might be an issue playing videos in this browser. We're working on better cross-brower experience, but in the meantime please try the latest Chrome or Firefox browsers. Or, you may be able to watch the video directly without progress tracking or transcript: