Understanding forms
Until now, we’ve dealt with URLs that render, in their main content block, a custom render array (/forecast/turin
, for example) or a render array that represents a node (the Home page or the Trip page).
But not all the routes follow this pattern. For example, the /user/login
route contains something different. By using WebProfiler, we can see that the controller used in this case is HtmlFormController
, which is in charge of returning a specialized version of a render array, called a form array. At the moment, the login form is functional, but it is unstyled:
Figure 7.1 – The unstyled login form
Figure 7.1 shows that the main content for the Log in page is a form.
HtmlFormController
is used to manage every form that must be rendered in the main content block, but how does Drupal know which form to render where? A form is identified by two properties:
- The fully qualified class name:
\Drupal\user\Form\UserLoginForm...