Form Factory Kits¶
Form Factory Kits is a Drupal module that builds Form API render arrays from
small PHP objects called kits. Each kit knows one Form API element type
(textfield, details, submit, ...) and exposes fluent setters for its
properties. When you are done, the kit returns a plain render array.
$form_factory = \Drupal::service('formfactory')->load($form);
$kits = \Drupal::service('formfactorykits');
$form_factory->append(
$kits->textField('name')
->setTitle('Name')
->setRequired()
);
$form_factory->append($kits->submit());
$form = $form_factory->getForm();
The result is an ordinary $form array. No kit object is left in it, so
everything downstream of the builder (form cache, AJAX, alter hooks,
rendering) works with a plain render array.
Where to start¶
- Installation: Composer, the beta dependency chain, enabling the module.
- Concepts: kits, the kits service, FormFactory, and how a kit becomes a render array.
- Guides: altering any
$formarray, forms withFormObjectBase, nesting. - Kit reference and trait reference: every kit and trait in
src/. - Writing your own kit.
Building these docs¶
The site is built with MkDocs and the Material theme. From the module root:
pip install -r docs/requirements.txt
mkdocs serve # live preview on http://127.0.0.1:8000
mkdocs build --strict # static site in build/docs-site/
build/ is ignored by Git. Pages are plain Markdown in docs/; add new pages
to the nav in mkdocs.yml. A push to 2.x that changes this tree or
mkdocs.yml publishes the site at
https://project.pages.drupalcode.org/formfactorykits/ via the GitLab Pages job.