phil / field-layout
Lay out edit forms in tabs and quarter-width rows, with per-placement texts and show or lock conditions the server enforces on every submit.
Requires
- php: >=8.5
- ext-mbstring: *
- phil/form-logic: ^0.1@dev
Requires (Dev)
- phpunit/phpunit: ^13.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-30 02:52:31 UTC
README
Lay out edit forms in tabs and quarter-width rows, with per-placement texts and show or lock conditions the server enforces on every submit.
phil/field-layout describes how an edit form is laid out, apart from the fields themselves: tabs, rows of four quarters, a label, instructions, a tip and a warning for each placement, and the conditions under which a placement is shown and editable. A field may be placed twice, each placement under a handle of its own; a set of placements — an address — may be imported several times, each time under a prefix.
The layout is declared by PHP attributes on a class, or by a definition as arrays, as a YAML or JSON file gives it. The
conditions are rules of the JsonLogic subset of phil/form-logic, checked when the layout is built: a condition reads
only the handles placed before it and the context variables the layout declares, such as whether the person editing is
staff, so one pass in reading order decides every placement.
The browser may replay the conditions to show, hide and lock fields as the form is filled; the server decides again
whatever the browser sent. LayoutJudge gives the state of each placement — editable, read-only or hidden — and the
values to validate and write: a hidden placement is neither validated nor written unless it is always saved, and a
read-only placement keeps its stored value whatever was submitted.
It is a plain PHP library, on phil/form-logic.
Status
| Part | State |
|---|---|
| Tabs, placements, widths in quarters, rows, texts per placement, a field placed twice | Implemented and tested |
| Field sets imported under a prefix, their conditions renamed | Implemented and tested |
| The definition as arrays, read strictly and bounded, and written back | Implemented, tested and fuzzed |
| The layout declared by attributes | Implemented and tested |
| Conditions to show and to edit a placement, their reading order, their types | Implemented and tested |
| The server's decision on a submission | Implemented and tested |
Documentation
| Document | What it covers |
|---|---|
| Installation | Requirements and installing. |
| Layouts | Tabs, placements, widths, texts, handles, field sets, attributes and the definition as arrays. |
| Conditions and submissions | Showing and locking placements, the context, the reading order, the browser and the server's decision. |
| Extension points | What an application may replace or add, and when it is stable. |
| Testing | The package's tests, its fuzz target and its benchmark. |
| Reference | Every public type, with its role. |
Quick start
composer require phil/field-layout
use Phil\FieldLayout\ArrayLayoutReader; use Phil\FieldLayout\LayoutJudge; $layout = new ArrayLayoutReader()->read([ 'context' => ['is_staff'], 'tabs' => [ ['name' => 'general', 'label' => 'General', 'fields' => [ ['field' => 'title', 'tip' => 'Shown in the catalogue.'], ['field' => 'price', 'width' => 2, 'editable_when' => ['var' => 'is_staff']], ['field' => 'has_prerequisite', 'width' => 2], ['field' => 'prerequisite', 'visible_when' => ['var' => 'has_prerequisite']], ]], ], ]); $decision = new LayoutJudge()->judge($layout, $submitted, $stored, ['is_staff' => $isStaff]); $decision->validated(); // the handles to validate $decision->values; // the values to write, nothing else
Requirements
PHP 8.5 or later with ext-mbstring.
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.