Forms with groups and access levels

One field layout drives the form, the record view and saving: groups, collapsed groups and fields that are writable, read-only or hidden – also per record.

The code

app/src/Controllers/ProjectController.php – defineFieldLayout() whole file
/**
* Groups of the form and the view. A project that is done keeps its
* budget read-only; the feedback comes from the client and is read-only.
*/
protected function defineFieldLayout(?DataObject $record): ?FieldLayout
{
$layout = FieldLayout::create()
->group('Project', ['Title', 'ClientID', 'TypeID', 'Tags', 'Status', 'Priority'], true, 'basics')
->group('Schedule and budget', ['StartDate', 'EndDate', 'Budget', 'ManagerID'], true, 'schedule')
->group('Description', ['Description'], true, 'description')
->group('Internal', ['InternalNote'], false, 'internal')
->group('Client feedback', ['FeedbackRating', 'FeedbackText', 'FeedbackAt'], false, 'feedback')
->setLevels([
'FeedbackRating' => FieldLayout::READ,
'FeedbackText' => FieldLayout::READ,
'FeedbackAt' => FieldLayout::READ,
]);
if ($record?->Status === 'done') {
$layout->setLevel('Budget', FieldLayout::READ);
}
return $layout;
}