Good morning,
Its a sunday morning and I am starting the day with a little brush up on my drupal 8 knowledge.
I am going to make a custom form, in that form I will make few fields and get default values from the saved configuration.
This configuration would be set from the form.
I would go on and make settings save in files which would make the configurations under version control.
Step 1: Creating custom form( form API).
Drupal has got a good documentation of form api, it gives you in detail information about how one can create custom forms.
In the previous post we had created a custom module `hello_world`.
To build a form in drupal 8 we use:
I will make a new routing file so that the form comes on a page.
Step 2:We will create another file which will contain call the class and logic for the form.
File would come as `modules/hello_world/src/Form/HelloWorldForm.php`. First we declare the namespace, the other classes we want to use, and extend the FormBase class.
We use to get code from some other classes, using the `use` PHP keyword and then the namespace, using the PSR-4 standard, which will autoload the classes in the files that correspond to these namespaces.
I have not used the validateForm which is used for form validations and
my submitForm function is also empty right now.
Right now I have got a custom form which has been made on route `hello_world/form`.
Which contains 2 textfields and a submit form.
Next step is to make a default config that would be loaded in these fields.
First name: Nitish
Last name: Guleria
Let us put this in next blog post.