Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/sections/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
);
},
'fields' => function () {
return $this->form->fields()->toProps();
return $this->form->fields()->toProps(fail: false);
}
],
'methods' => [
Expand Down
26 changes: 23 additions & 3 deletions src/Form/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
use Kirby\Cms\ModelWithContent;
use Kirby\Exception\FormValidationException;
use Kirby\Exception\NotFoundException;
use Kirby\Filesystem\F;
use Kirby\Form\Field\BaseField;
use Kirby\Form\Field\InfoField;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Collection;
use Kirby\Toolkit\Str;
use Throwable;

/**
* A collection of Field objects
Expand Down Expand Up @@ -366,15 +369,32 @@ public function toFormValues(): array
*
* @since 5.0.0
*/
public function toProps(bool $defaults = false): array
{
public function toProps(
bool $defaults = false,
bool $fail = true
): array {
$fields = $this->data;
$props = [];
$language = $this->language();
$permissions = $this->model->permissions()->can('update');

foreach ($fields as $name => $field) {
$props[$name] = $field->toArray();
try {
$props[$name] = $field->toArray();
} catch (Throwable $e) {
if ($fail === true) {
throw $e;
}

$root = $this->kirby()->environment()->get('DOCUMENT_ROOT');
$props[$name] = (new InfoField(
label: $e,
icon: 'alert',
text: $e->getMessage() . ' in file: ' . F::relativepath($e->getFile(), $root) . ' (line ' . $e->getLine() . ')',
Copy link
Member Author

@distantnative distantnative Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want a a helper method somewhere centrally that always resolves the F::relativepath() with the document root.

theme: 'negative',
))->toArray();
continue;
}

// the field should be disabled in the form if the user
// has no update permissions for the model or if the field
Expand Down
Loading