- Create an src folder in your module directory. In this directory, create a Form directory, which will hold the class that defines your form.
- Next, create a file called ExampleForm.php in your module's src/Form directory.
Drupal utilizes PSR4 to discover and autoload classes. For brevity, this defines that there should be one class per file, with each filename matching the class name. The folder structure will also mimic the namespace expected.
- We will edit the ExampleForm.php file and add the proper PHP namespace, classes used, and the class itself:
<?php namespace Drupal\drupalform\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; class ExampleForm extends FormBase { }
The namespace defines ...