phil / custom-fields-bundle
Give custom fields a Symfony edit form and Twig display that show each value only to people allowed to see it, with schemas from JSON files or your store.
Package info
github.com/parler-haut-interagir-librement/custom-fields-bundle
Type:symfony-bundle
pkg:composer/phil/custom-fields-bundle
Requires
- php: >=8.5
- phil/custom-fields: ^0.1@dev
- symfony/config: ^8.2
- symfony/dependency-injection: ^8.2
- symfony/form: ^8.2
- symfony/options-resolver: ^8.2
- symfony/security-core: ^8.2
- symfony/service-contracts: ^3.8
- symfony/translation-contracts: ^3.8
Requires (Dev)
- phpunit/phpunit: ^13.4
- symfony/console: ^8.2
- symfony/css-selector: ^8.2
- symfony/dom-crawler: ^8.2
- symfony/event-dispatcher: ^8.2
- symfony/framework-bundle: ^8.2
- symfony/http-kernel: ^8.2
- symfony/translation: ^8.2
- symfony/twig-bridge: ^8.2
- symfony/twig-bundle: ^8.2
- twig/twig: ^3.31.1
Suggests
- symfony/console: For phil:custom-fields:lint
- symfony/security-bundle: For the permissions of restricted fields and of the staff audience
- twig/twig: For custom_field_set(), custom_field_values() and the form theme
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-30 02:53:14 UTC
README
Give custom fields a Symfony edit form and Twig display that show each value only to people allowed to see it, with schemas from JSON files or your store.
phil/custom-fields-bundle integrates phil/custom-fields with Symfony. The library describes the extra fields of a kind of record — a course, a learner, a product — as data, checks the values and decides who sees each one; the bundle gives it a form, templates, a place to keep the definitions and the permissions of Symfony Security. The library alone suits an application without Symfony.
- Schemas by name: the fields every record of a kind has and its kits, read from versioned JSON files named in the configuration, or from the application's own sources — a settings table, an import —, read once per request.
- A generated edit form:
CustomFieldsTypebuilds one field per custom field the person may edit, of the right Symfony type, with the browser's bounds, grouped by section in fieldsets. The library's validator checks the whole record, and its violations are shown beside their fields, in English or French. - Nothing lost, nothing leaked: the values the form does not show keep their stored value, a secret is never written back into the page and keeps its value when left empty, and a formula is never edited.
- Who sees what: restricted fields ask Symfony Security for their permission, and the staff audience — internal
fields, secret ones to write — is granted only to whoever holds the staff permission,
ROLE_ADMINby default, even when a page asks for it. - Values in Twig:
custom_field_values()reads the stored values back, formulas computed, and keeps those the person sees;@PhilCustomFields/values.html.twigshows them as description lists by section. - Checked before a deployment:
phil:custom-fields:lintreads every schema and builds its field set with each of its kits. - Worker-safe and fast: the schemas read for a request are forgotten by the kernel's reset; a page of a hundred fields with twenty formulas reads its values in about 0.22 ms.
Status
| Part | State |
|---|---|
PhilCustomFieldsBundle and its configuration phil_custom_fields |
Implemented and tested |
| Schemas from JSON files and from the application's sources | Implemented and tested |
| The edit form and its theme | Implemented and tested |
| The values in Twig | Implemented and tested |
| The permissions and the staff audience | Implemented and tested |
| The lint command | Implemented and tested |
Documentation
| Document | What it covers |
|---|---|
| Installation | Requirements, installing, a first schema. |
| Configuration | Every option, with an example. |
| Schemas | JSON files, the application's own sources, kits by category, the lint command. |
| Forms | The edit form, its options, what a submission gives, and its theme. |
| Templates | The field set and the values of a record in Twig. |
| Visibility | Audiences, the staff permission, restricted and secret fields. |
| Extension points | The services to replace, the tags to add to, and when they are stable. |
| Testing | The bundle's tests and its benchmark. |
| Reference | Every class and service of the bundle. |
Quick start
// config/bundles.php Phil\CustomFieldsBundle\PhilCustomFieldsBundle::class => ['all' => true],
# config/packages/phil_custom_fields.yaml phil_custom_fields: schemas: course: fields: '%kernel.project_dir%/config/custom_fields/course.json'
use Phil\CustomFieldsBundle\Infrastructure\Form\CustomFieldsType; $builder->add('fields', CustomFieldsType::class, ['schema' => 'course', 'categories' => [$course->category]]);
{{ include('@PhilCustomFields/values.html.twig', {
values: custom_field_values(custom_field_set('course', [course.category]), course.fields),
}) }}
Requirements
PHP 8.5 or later and Symfony 8.2 or later. Twig shows the form theme and the values; the Console runs the lint command; SecurityBundle decides the permissions.
Contributing
Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.
License
MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Parler Haut Interagir Librement project. See LICENSE.