Skip to content

Commit 76d283c

Browse files
committed
Refactor dialogs + drawers as classes
1 parent 6891eaf commit 76d283c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2641
-1674
lines changed

config/areas/account/dialogs.php

Lines changed: 15 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,64 @@
11
<?php
22

3-
use Kirby\Panel\UserTotpEnableDialog;
3+
use Kirby\Panel\Ui\Dialogs\UserTotpEnableDialog;
44

55
$dialogs = require __DIR__ . '/../users/dialogs.php';
66

77
return [
8-
// change email
98
'account.changeEmail' => [
109
'pattern' => '(account)/changeEmail',
11-
'load' => $dialogs['user.changeEmail']['load'],
12-
'submit' => $dialogs['user.changeEmail']['submit'],
10+
...$dialogs['user.changeEmail']
1311
],
14-
15-
// change language
1612
'account.changeLanguage' => [
1713
'pattern' => '(account)/changeLanguage',
18-
'load' => $dialogs['user.changeLanguage']['load'],
19-
'submit' => $dialogs['user.changeLanguage']['submit'],
14+
...$dialogs['user.changeLanguage']
2015
],
21-
22-
// change name
2316
'account.changeName' => [
2417
'pattern' => '(account)/changeName',
25-
'load' => $dialogs['user.changeName']['load'],
26-
'submit' => $dialogs['user.changeName']['submit'],
18+
...$dialogs['user.changeName']
2719
],
28-
29-
// change password
3020
'account.changePassword' => [
3121
'pattern' => '(account)/changePassword',
32-
'load' => $dialogs['user.changePassword']['load'],
33-
'submit' => $dialogs['user.changePassword']['submit'],
22+
...$dialogs['user.changePassword']
3423
],
35-
36-
// change role
3724
'account.changeRole' => [
3825
'pattern' => '(account)/changeRole',
39-
'load' => $dialogs['user.changeRole']['load'],
40-
'submit' => $dialogs['user.changeRole']['submit'],
26+
...$dialogs['user.changeRole']
4127
],
42-
43-
// delete
4428
'account.delete' => [
4529
'pattern' => '(account)/delete',
46-
'load' => $dialogs['user.delete']['load'],
47-
'submit' => $dialogs['user.delete']['submit'],
30+
...$dialogs['user.delete']
4831
],
49-
50-
// account fields dialogs
5132
'account.fields' => [
5233
'pattern' => '(account)/files/(:any)/fields/(:any)/(:all?)',
53-
'load' => $dialogs['user.fields']['load'],
54-
'submit' => $dialogs['user.fields']['submit']
34+
...$dialogs['user.fields']
5535
],
56-
57-
// change file name
5836
'account.file.changeName' => [
5937
'pattern' => '(account)/files/(:any)/changeName',
60-
'load' => $dialogs['user.file.changeName']['load'],
61-
'submit' => $dialogs['user.file.changeName']['submit'],
38+
...$dialogs['user.file.changeName']
6239
],
63-
64-
// change file sort
6540
'account.file.changeSort' => [
6641
'pattern' => '(account)/files/(:any)/changeSort',
67-
'load' => $dialogs['user.file.changeSort']['load'],
68-
'submit' => $dialogs['user.file.changeSort']['submit'],
42+
...$dialogs['user.file.changeSort']
6943
],
70-
71-
// change file template
7244
'account.file.changeTemplate' => [
7345
'pattern' => '(account)/files/(:any)/changeTemplate',
74-
'load' => $dialogs['user.file.changeTemplate']['load'],
75-
'submit' => $dialogs['user.file.changeTemplate']['submit'],
46+
...$dialogs['user.file.changeTemplate']
7647
],
77-
78-
// delete
7948
'account.file.delete' => [
8049
'pattern' => '(account)/files/(:any)/delete',
81-
'load' => $dialogs['user.file.delete']['load'],
82-
'submit' => $dialogs['user.file.delete']['submit'],
50+
...$dialogs['user.file.delete']
8351
],
84-
85-
// account file fields dialogs
8652
'account.file.fields' => [
8753
'pattern' => '(account)/files/(:any)/fields/(:any)/(:all?)',
88-
'load' => $dialogs['user.file.fields']['load'],
89-
'submit' => $dialogs['user.file.fields']['submit']
54+
...$dialogs['user.file.fields']
9055
],
91-
92-
// account enable TOTP
9356
'account.totp.enable' => [
9457
'pattern' => '(account)/totp/enable',
95-
'load' => fn () => (new UserTotpEnableDialog())->load(),
96-
'submit' => fn () => (new UserTotpEnableDialog())->submit()
58+
'handler' => fn () => new UserTotpEnableDialog()
9759
],
98-
99-
// account disable TOTP
10060
'account.totp.disable' => [
10161
'pattern' => '(account)/totp/disable',
102-
'load' => $dialogs['user.totp.disable']['load'],
103-
'submit' => $dialogs['user.totp.disable']['submit']
62+
...$dialogs['user.totp.disable']
10463
],
10564
];

config/areas/account/drawers.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@
33
$drawers = require __DIR__ . '/../users/drawers.php';
44

55
return [
6-
// account fields drawers
76
'account.fields' => [
87
'pattern' => '(account)/files/(:any)/fields/(:any)/(:all?)',
9-
'load' => $drawers['user.fields']['load'],
10-
'submit' => $drawers['user.fields']['submit']
8+
...$drawers['user.fields']
119
],
12-
13-
// account file fields drawers
1410
'account.file.fields' => [
1511
'pattern' => '(account)/files/(:any)/fields/(:any)/(:all?)',
16-
'load' => $drawers['user.file.fields']['load'],
17-
'submit' => $drawers['user.file.fields']['submit']
12+
...$drawers['user.file.fields']
1813
],
1914
];

config/areas/fields/dialogs.php

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,12 @@
11
<?php
22

3-
use Kirby\Cms\Find;
4-
use Kirby\Panel\Field;
3+
use Kirby\Panel\Ui\Dialogs\FieldDialog;
54

65
return [
76
'model' => [
8-
'load' => function (
9-
string $modelPath,
10-
string $fieldName,
11-
string|null $path = null
12-
) {
13-
return Field::dialog(
14-
model: Find::parent($modelPath),
15-
fieldName: $fieldName,
16-
path: $path,
17-
method: 'GET'
18-
);
19-
},
20-
'submit' => function (
21-
string $modelPath,
22-
string $fieldName,
23-
string|null $path = null
24-
) {
25-
return Field::dialog(
26-
model: Find::parent($modelPath),
27-
fieldName: $fieldName,
28-
path: $path,
29-
method: 'POST'
30-
);
31-
}
7+
'handler' => FieldDialog::forModel(...)
328
],
339
'file' => [
34-
'load' => function (
35-
string $modelPath,
36-
string $filename,
37-
string $fieldName,
38-
string|null $path = null
39-
) {
40-
return Field::dialog(
41-
model: Find::file($modelPath, $filename),
42-
fieldName: $fieldName,
43-
path: $path,
44-
method: 'GET'
45-
);
46-
},
47-
'submit' => function (
48-
string $modelPath,
49-
string $filename,
50-
string $fieldName,
51-
string|null $path = null
52-
) {
53-
return Field::dialog(
54-
model: Find::file($modelPath, $filename),
55-
fieldName: $fieldName,
56-
path: $path,
57-
method: 'POST'
58-
);
59-
}
10+
'handler' => FieldDialog::forFile(...)
6011
],
6112
];

config/areas/fields/drawers.php

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,12 @@
11
<?php
22

3-
use Kirby\Cms\Find;
4-
use Kirby\Panel\Field;
3+
use Kirby\Panel\Ui\Drawers\FieldDrawer;
54

65
return [
76
'model' => [
8-
'load' => function (
9-
string $modelPath,
10-
string $fieldName,
11-
string|null $path = null
12-
) {
13-
return Field::drawer(
14-
model: Find::parent($modelPath),
15-
fieldName: $fieldName,
16-
path: $path,
17-
method: 'GET'
18-
);
19-
},
20-
'submit' => function (
21-
string $modelPath,
22-
string $fieldName,
23-
string|null $path = null
24-
) {
25-
return Field::drawer(
26-
model: Find::parent($modelPath),
27-
fieldName: $fieldName,
28-
path: $path,
29-
method: 'POST'
30-
);
31-
}
7+
'handler' => FieldDrawer::forModel(...)
328
],
339
'file' => [
34-
'load' => function (
35-
string $modelPath,
36-
string $filename,
37-
string $fieldName,
38-
string|null $path = null
39-
) {
40-
return Field::drawer(
41-
model: Find::file($modelPath, $filename),
42-
fieldName: $fieldName,
43-
path: $path,
44-
method: 'GET'
45-
);
46-
},
47-
'submit' => function (
48-
string $modelPath,
49-
string $filename,
50-
string $fieldName,
51-
string|null $path = null
52-
) {
53-
return Field::drawer(
54-
model: Find::file($modelPath, $filename),
55-
fieldName: $fieldName,
56-
path: $path,
57-
method: 'POST'
58-
);
59-
}
10+
'handler' => FieldDrawer::forFile(...)
6011
],
6112
];

0 commit comments

Comments
 (0)