inixmedia / kern-ux-form-theme
Symfony form theme for KERN UX, the design system for German public administration (https://www.kern-ux.de)
Package info
github.com/svenpet90/kern-ux-form-theme
Type:symfony-bundle
pkg:composer/inixmedia/kern-ux-form-theme
Requires
- php: >=8.1
- symfony/http-kernel: ^6.4 || ^7.4 || ^8.1
- twig/twig: ^3.10 || ^4.0
Requires (Dev)
- phpunit/phpunit: ^10.5 || ^11.0
- symfony/form: ^6.4 || ^7.4 || ^8.1
- symfony/translation-contracts: ^3.0
- symfony/twig-bridge: ^6.4 || ^7.4 || ^8.1
- vincentlanglet/twig-cs-fixer: ^3.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A Symfony form theme that renders forms with the markup of
KERN UX, the open design system for
German public administration — analogous to Symfony's built-in
bootstrap_5_layout.html.twig.
The theme covers the KERN form components: text inputs, textareas, selects,
radio/checkbox groups (as kern-fieldset), single checkboxes, buttons, hints,
and error messages (inline kern-error per field, kern-alert on the root
form). Following the KERN guidelines it marks optional fields instead of
required ones and uses aria-required rather than the native required
attribute.
Note: This package ships markup only. Your application must include the KERN UX styles itself, e.g. via
@kern-ux/native.
Requirements
- PHP 8.1+ (PHP 8.4+ for Symfony 8)
- Symfony 6.4, 7.x or 8.x (
symfony/form+symfony/twig-bridge)
Installation
composer require inixmedia/kern-ux-form-theme
If you don't use Symfony Flex, register the bundle manually:
// config/bundles.php return [ // ... Inixmedia\KernUxFormTheme\KernUxFormThemeBundle::class => ['all' => true], ];
Usage
Enable the theme globally:
# config/packages/twig.yaml twig: form_themes: - '@KernUxFormTheme/kern_layout.html.twig'
Or per template:
{% form_theme form '@KernUxFormTheme/kern_layout.html.twig' %}
{{ form(form) }}
Rendered markup
A simple text field row renders as:
<div class="kern-form-input"> <label class="kern-label" for="form_name">Vorname</label> <div class="kern-hint" id="form_name_help">Wie im Ausweis angegeben</div> <input class="kern-form-input__input" id="form_name" name="form[name]" aria-required="true" aria-describedby="form_name_help" type="text"> </div>
Expanded choices become a KERN fieldset:
<fieldset class="kern-fieldset"> <legend class="kern-label kern-label--large">Anrede</legend> <div class="kern-fieldset__body" id="form_salutation"> <div class="kern-form-check"> <input class="kern-form-check__radio" type="radio" ...> <label class="kern-label" for="...">Frau</label> </div> ... </div> </fieldset>
Errors on the root form render as a KERN alert:
<div class="kern-alert kern-alert--danger" role="alert"> <div class="kern-alert__header"> <span class="kern-icon kern-icon--danger" aria-hidden="true"></span> <h2 class="kern-title">Das Formular enthält Fehler</h2> </div> <div class="kern-alert__body"> <p class="kern-body">Etwas ist schiefgelaufen.</p> </div> </div>
Errors on a single field render inline instead, wired to the input through
aria-describedby.
Customisation
Error summary heading
When the root form has errors, the theme renders a KERN alert whose title is a
heading. A heading — rather than a <span> — is what lets screen reader users jump
straight to the summary instead of tabbing through the form. KERN permits it here
because the title is followed by the error list; an alert with no following content
has to stay a paragraph (BITV criterion 9.1.3.1a).
The level defaults to h2. Since the right level depends on the surrounding
document outline, set it per project:
# config/packages/twig.yaml twig: globals: kern_error_summary_element: 'h3'
For anything beyond the element, override the blocks in your own theme:
{% use '@KernUxFormTheme/kern_layout.html.twig' %}
{%- block form_errors_summary_title -%}
Bitte korrigieren Sie die folgenden Angaben
{%- endblock -%}
form_errors_summary wraps the whole alert, form_errors_summary_title only its
text.
Translations
The two strings the theme contributes itself — the error summary title and the
(optional) marker — go through the translator under the KernUxFormTheme domain.
German and English catalogues ship with the bundle.
The message ids are the German wordings, so an application that configures nothing renders exactly what the theme rendered before. To change or add a language, define the same ids in your own catalogue:
<!-- translations/KernUxFormTheme.fr.xlf --> <trans-unit id="form_errors_summary_title"> <source>Das Formular enthält Fehler</source> <target>Le formulaire contient des erreurs</target> </trans-unit>
Error messages themselves come from your validation constraints and are translated by Symfony as usual; the theme does not touch them.
Development
composer install # Run the test suite (renders real forms through the theme) composer test # Lint the Twig templates composer lint
License
Released under the MIT License.
KERN UX itself is developed by the German federal and state governments; see kern-ux.de for the design system's own licensing.