nowo-tech / form-kit-bundle
Symfony bundle to reduce repetitive form field options: convention-based labels/placeholder/help (form_snake.field_snake.*), configurable attr/row_attr/translation_domain, and cascading option merge (global → field type → form → field). Symfony 6|7|8.
Package info
github.com/nowo-tech/FormKitBundle
Type:symfony-bundle
pkg:composer/nowo-tech/form-kit-bundle
Requires
- php: >=8.1
- a2lix/translation-form-bundle: ^3.2 || ^4.0
- doctrine/collections: ^2.2
- symfony/config: ^6.4 || ^7.0 || ^8.0
- symfony/dependency-injection: ^6.4 || ^7.0 || ^8.0
- symfony/form: ^6.4 || ^7.0 || ^8.0
- symfony/http-kernel: ^6.4 || ^7.0 || ^8.0
- symfony/translation: ^6.4 || ^7.0 || ^8.0
- symfony/yaml: ^6.4 || ^7.0 || ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^10.0 || ^11.0
- symfony/framework-bundle: ^6.4 || ^7.0 || ^8.0
This package is not auto-updated.
Last update: 2026-03-04 10:13:41 UTC
README
Symfony bundle to reduce repetitive form field options: convention-based translation keys (form_snake.field_snake.label, .placeholder, .help), configurable defaults and multiple configs via YAML, and cascading option merge (global → field type → form → field).
Compatible with Symfony 6.4, 7.x and 8.x (PHP 8.1+).
Features
- Convention-based labels, placeholder and help: Default translation keys are
{form_snake}.{field_snake}.label,.placeholder,.help. Set any tofalsein field options to disable. - Multiple configs: Define named configs (e.g.
default,bootstrap) withtranslation_domain,defaults.attr,defaults.row_attr, and per-field-type options. Choose the active config per form viasetFormKitConfigName(). - Cascading merge: Options are merged in order: config defaults → field type → field options. Explicit field options override.
- Trait or base class: Use FormOptionsTrait with FormOptionsMerger (inject via service), or extend FormKitAbstractType for snake_case type names with FormTypeMap (same option-merging model via FormOptionsMerger).
- Phase 2 helpers:
addText(),addEmail(),addTextarea(),addPassword(),addUrl(),addInteger(),addNumber(),addCheckbox(),addChoice()— pass only field name and options. - Build from array:
buildFormFromArray($builder, $fields)— define all fields in one array (type as FQCN with FormOptionsTrait, or snake_case with FormKitTrait). - Optional types: Built-in type map includes optional Symfony UX types (e.g. Dropzone, Cropper) and A2lix Translations when the corresponding package is installed. Extend via
type_mapin config.
Installation
composer require nowo-tech/form-kit-bundle
With Flex, the recipe creates config/packages/nowo_form_kit.yaml. Otherwise register the bundle in config/bundles.php and add the config file manually. See docs/INSTALLATION.md.
Quick usage
-
Configure (optional) — edit
config/packages/nowo_form_kit.yaml: setdefault_config,configs(each withalias,translation_domain,defaults,field_types), and optionallytype_mapfor custom or UX types. -
Register your form as a service and inject FormOptionsMerger:
# config/services.yaml App\Form\UserProfileType: tags: ['form.type'] calls: - setFormOptionsMerger: ['@Nowo\FormKitBundle\Form\FormOptionsMerger']
- Use the trait in your form type (Phase 2 or array):
use Nowo\FormKitBundle\Form\FormOptionsTrait; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; class UserProfileType extends AbstractType { use FormOptionsTrait; public function buildForm(FormBuilderInterface $builder, array $options): void { $this->addText($builder, 'full_name', []); $this->addEmail($builder, 'email_address', []); // Or: $this->buildFormFromArray($builder, ['full_name' => TextType::class, 'email_address' => EmailType::class]); } }
- Add translations for keys like
user_profile.full_name.label,user_profile.full_name.placeholder,user_profile.full_name.helpin your translation domain.
Demos
The bundle includes demos (Symfony 6, 7, 8) with:
- FormType example (all field types, built from array).
- Form built in the controller using
FormOptionsMerger::resolve(). - Search form — inline/horizontal layout (search bar).
- Example form — card/stacked layout.
Run a demo via Docker/Make from the bundle root; see docs/CONTRIBUTING.md.
For CSS frameworks, see docs/USAGE.md for ready-to-use configuration examples for Bootstrap 5 and Tailwind CSS.
Documentation
License
MIT. See LICENSE.