Commit Graph
22 Commits
Author SHA1 Message Date
Sky Mulleyandrobert dennis 71dd1911a5 Implement native support for hooking into forms with extensions (#7256)
## Problem

Extensions can render content before and after most admin pages, but not
inside the forms on them. The only exception was
`panel.users.detail.form`, and it could only re-render or validate the
user's existing fields. An extension had no way to add a field of its
own, because the Panel's save requests had nowhere to carry the value
and nothing loaded it back.

## Changes

### Slots inside every admin form

The create and edit forms for users, nodes, servers, eggs, locations,
mounts and database hosts each render a slot inside the form, such as
`panel.servers.create.form` and `panel.servers.detail.details.form`. The
slot receives the native `form`, the form's `kind` (`admin.server`), and
`mode` (`'create'` or `'edit'`). Edit slots also receive the saved
`resource`. Contributed `form.AppField` controls share the form's
validation, pending state and submit action.

### Extension-owned fields

An extension registers fields in its provider:

```php
$this->registerFormFields('admin.user', ['plan' => ['required', 'in:free,pro']]);

$this->registerFormFields(
    'admin.node',
    ['region' => ['required', 'string', 'max:32']],
    fn (Node $node): array => ['region' => NodeRegion::for($node)],
    fn (Node $node, array $values) => NodeRegion::store($node, $values['region']),
);
```

The 14 create and update endpoints accept an optional `extensions: {
[extensionId]: { [field]: value } }` body field. Each extension's rules
are applied as `extensions.{id}.{field}`, and only when the request
includes that extension's values. The extension's `save` callback runs
in the same database transaction as the core change, so a failure rolls
both back.

Server creation is the exception. Wings reads the new server while
provisioning it, so extension values are saved after provisioning
succeeds, outside the transaction.

For Node updates when Wings is unreachable. `UpdateNode` saves the node
and then throws `ConfigurationNotPersistedException` as a warning. The
node controller defers that exception until the extension values are
saved, so the node update is no longer rolled back.

`GET /api/admin/extensions/forms/{form}/{id}` returns every extension's
current values. It requires the resource's read permission. Edit pages
fetch it before rendering the form, but only when an extension has
registered fields for that form; the bootstrap payload now lists them
per extension in `forms`.

For users and servers the callbacks are optional, and values are stored
in the extension's scoped settings (`settings()->forUser($user)`,
`forServer($server)`). Values are limited to strings, numbers, booleans,
`null`, or lists of strings and numbers, which keeps the OpenAPI schema
and generated types concrete.

A `load` callback that throws, or returns an invalid value, is recorded
against the extension in the `form` phase. The frontend then hides that
extension's slot contributions on the edit page, so a save cannot
overwrite its stored values with defaults. Fields of a disabled or
failed extension are neither validated, saved nor loaded.

---------

Co-authored-by: robert dennis <31261583+robertdrakedennis@users.noreply.github.com>
2026-10-09 01:26:45 -04:00
6c0413e39b Start 2.0 development
Co-authored-by: Anthony <anthony@infraly.co>
Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
2026-10-05 18:10:18 -04:00
Matthew PennerandDaneEveritt cbcf62086f Upgrade to Laravel 9 (#4413)
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
2022-10-14 10:59:20 -06:00
DaneEveritt 5705d7dbdd Run php-cs-fixer 2022-05-14 16:03:50 -04:00
DaneEveritt 4252014d18 Update includes definition to match updated package requirements 2022-05-04 19:11:42 -04:00
Dane Everitt 5fdb0a5909 Correctly expose OOM disable state for a server 2021-09-13 21:02:12 -07:00
Dane Everitt 663143de0b Merge branch 'develop' into dane/restore-backups 2021-01-25 19:16:40 -08:00
Dane Everitt c449ca5155 Use more standardized phpcs 2021-01-23 12:33:34 -08:00
Dane Everitt b38b8f6465 Mark some fields as deprecated in the API 2021-01-17 16:02:11 -08:00
Dane Everitt a75a347d65 Remove suspended & installing fields, replace with single status field 2021-01-17 15:51:56 -08:00
Matthew Penner e6c4a68e4a Update logic for tracking a server's transfer state 2020-12-17 10:35:54 -07:00
Dane Everitt 3c7ffaaadb Remove all references of packs from the Panel 2020-09-13 11:13:37 -07:00
Dane Everitt f1c3762f4d Add base support for definining the number of backups that can be created for a server 2020-04-26 12:12:29 -07:00
AreYouScared b351c07d34 Fix server transformer
Properly pass the value to wings
2020-03-29 16:55:06 -04:00
Stepan Fedotov 5f60a6c735 Fix the resource key for subusers 2019-12-28 13:53:33 +02:00
TrixterTheTux ab09c7db28 Fix couple of issues with /api/application/servers 2019-08-31 11:29:44 +03:00
Dane Everitt 87b96bdfc8 Add core logic to allow for limited databases and allocations 2018-03-01 20:08:27 -06:00
Dane Everitt ab2973c4d1 Add pack transformer support 2018-03-01 18:43:39 -06:00
Dane Everitt e28973bcae Move everything around as needed to get things setup for the client API 2018-02-25 15:30:56 -06:00
Dane Everitt 633bba6d6e Add support for external_id on servers, closes #975 2018-02-24 11:57:12 -06:00
Dane Everitt 2bd691efad Add database list endpoint, add more resource name magic 2018-01-25 21:26:06 -06:00
Dane Everitt a497a3d153 Make server listing and single server view API endpoints work 2018-01-19 21:47:06 -06:00