Form

Some extra's for form components.

Better classes

The classes on a form has been changed to:

{%
  set classes = [
    'form',
    'form--' ~ element['#form_id']|clean_class
  ]
%}

Which gives you the following classes:

.form {}
.forn--user-login-form {}

Extra template suggestions

Added a more specific template suggestion. One based upon the ID of the form.

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'form' -->
<!-- FILE NAME SUGGESTIONS:
   x form--user-login-form.html.twig
   * form.html.twig
-->

In above example:

  • user-login-form is the ID of the form

Extra functions

Create the possibility to have form-specific preprocess functions.

So inside form--user-login-form.theme you could now have this function:

<?php

/**
 * Implements template_preprocess_hook().
 */
function compony_preprocess_form__user_login_form(&$variables, $hook) {
  // Do custom preprocessing here, 
  // only for the user-login-form. 
}

(Docs: Extending hooks yourself)

Specifications

Machine name

form

Built upon

Drupal Core

Perks

Responsive
Accessible

Building blocks

HTML

Stats

Public component
13 downloads
No open issue

Contributors