Skip to content

Commit dfc5fcc

Browse files
committed
feat: Models picker dialogs + Vue components
1 parent 166a400 commit dfc5fcc

29 files changed

+569
-823
lines changed

config/fields/files.php

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

33
use Kirby\Cms\ModelWithContent;
4+
use Kirby\Panel\Controller\Dialog\FilesPickerDialogController;
45

56
return [
67
'mixins' => [
7-
'filepicker',
88
'layout',
99
'min',
1010
'picker',
@@ -21,7 +21,8 @@
2121
'placeholder' => null,
2222

2323
/**
24-
* Sets the file(s), which are selected by default when a new page is created
24+
* Sets the file(s), which are selected by default
25+
* when a new page is created
2526
*/
2627
'default' => function ($default = null) {
2728
return $default;
@@ -48,9 +49,6 @@
4849
'parent' => function () {
4950
return $this->parentModel->apiUrl(true);
5051
},
51-
'query' => function () {
52-
return $this->query ?? $this->parentModel::CLASS_ALIAS . '.files';
53-
},
5452
'default' => function () {
5553
return $this->toFormValues($this->default);
5654
},
@@ -60,51 +58,46 @@
6058
],
6159
'methods' => [
6260
'toModel' => function (string $id) {
63-
return $this->kirby()->file($id, $this->model());
61+
return $this->kirby()->file($id, $this->model);
6462
}
6563
],
66-
'api' => function () {
67-
return [
68-
[
69-
'pattern' => '/',
70-
'action' => function () {
71-
$field = $this->field();
72-
73-
return $field->filepicker([
74-
'image' => $field->image(),
75-
'info' => $field->info(),
76-
'layout' => $field->layout(),
77-
'limit' => $field->limit(),
78-
'page' => $this->requestQuery('page'),
79-
'query' => $field->query(),
80-
'search' => $this->requestQuery('search'),
81-
'text' => $field->text()
82-
]);
83-
}
84-
],
85-
[
86-
'pattern' => 'upload',
87-
'method' => 'POST',
88-
'action' => function () {
89-
$field = $this->field();
90-
$uploads = $field->uploads();
64+
'api' => fn () => [
65+
[
66+
'pattern' => 'items',
67+
'method' => 'GET',
68+
'action' => fn () => $this->field()->itemsFromRequest()
69+
],
70+
[
71+
'pattern' => 'upload',
72+
'method' => 'POST',
73+
'action' => function () {
74+
$field = $this->field();
9175

92-
// move_uploaded_file() not working with unit test
93-
// @codeCoverageIgnoreStart
94-
return $field->upload($this, $uploads, function ($file, $parent) use ($field) {
95-
return $file->panel()->pickerData([
96-
'image' => $field->image(),
97-
'info' => $field->info(),
98-
'layout' => $field->layout(),
99-
'model' => $field->model(),
100-
'text' => $field->text(),
101-
]);
102-
});
103-
// @codeCoverageIgnoreEnd
104-
}
105-
]
106-
];
107-
},
76+
// move_uploaded_file() not working with unit test
77+
// @codeCoverageIgnoreStart
78+
return $field->upload(
79+
$this,
80+
$field->uploads(),
81+
fn ($file, $parent) => $field->toItem($file)
82+
);
83+
// @codeCoverageIgnoreEnd
84+
}
85+
]
86+
],
87+
'dialogs' => fn () => [
88+
'picker' => fn () => new FilesPickerDialogController(...[
89+
'model' => $this->model(),
90+
'hasSearch' => $this->search,
91+
'image' => $this->image,
92+
'info' => $this->info ?? false,
93+
'limit' => $this->limit,
94+
'max' => $this->max,
95+
'multiple' => $this->multiple,
96+
'query' => $this->query,
97+
'text' => $this->text,
98+
...$this->picker
99+
])
100+
],
108101
'save' => function ($value = null) {
109102
return $this->toStoredValues($value);
110103
},

config/fields/mixins/filepicker.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

config/fields/mixins/pagepicker.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

config/fields/mixins/picker.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@
5959
return $multiple;
6060
},
6161

62+
/**
63+
* Additional picker dialog props
64+
* @since 6.0.0
65+
* @values { image, layout, size }
66+
*/
67+
'picker' => function (array $picker = []) {
68+
return $picker;
69+
},
70+
6271
/**
6372
* Query for the items to be included in the picker
6473
*/
@@ -98,6 +107,12 @@
98107
'getIdFromArray' => function (array $array) {
99108
return $array['uuid'] ?? $array['id'] ?? null;
100109
},
110+
'itemsFromRequest' => function () {
111+
$ids = $this->kirby()->request()->get('items');
112+
$ids = Str::split($ids);
113+
$models = $this->toModels($ids);
114+
return $this->toItems($models);
115+
},
101116
'toItem' => function (ModelWithContent $model) {
102117
return $model->panel()->pickerData([
103118
'image' => $this->image,
@@ -125,7 +140,7 @@
125140
}
126141

127142
if ($id !== null && ($model = $this->toModel($id))) {
128-
$items[] = $this->toItem($model);
143+
$ids[] = $model->id();
129144
}
130145
}
131146

config/fields/mixins/userpicker.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

config/fields/pages.php

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

3-
use Kirby\Toolkit\A;
3+
use Kirby\Panel\Controller\Dialog\PagesPickerDialogController;
44

55
return [
66
'mixins' => [
77
'layout',
88
'min',
9-
'pagepicker',
109
'picker',
1110
],
1211
'props' => [
@@ -55,29 +54,28 @@
5554
return $this->kirby()->page($id);
5655
}
5756
],
58-
'api' => function () {
59-
return [
60-
[
61-
'pattern' => '/',
62-
'action' => function () {
63-
$field = $this->field();
64-
65-
return $field->pagepicker([
66-
'image' => $field->image(),
67-
'info' => $field->info(),
68-
'layout' => $field->layout(),
69-
'limit' => $field->limit(),
70-
'page' => $this->requestQuery('page'),
71-
'parent' => $this->requestQuery('parent'),
72-
'query' => $field->query(),
73-
'search' => $this->requestQuery('search'),
74-
'subpages' => $field->subpages(),
75-
'text' => $field->text()
76-
]);
77-
}
78-
]
79-
];
80-
},
57+
'api' => fn () => [
58+
[
59+
'pattern' => 'items',
60+
'method' => 'GET',
61+
'action' => fn () => $this->field()->itemsFromRequest()
62+
],
63+
],
64+
'dialogs' => fn () => [
65+
'picker' => fn () => new PagesPickerDialogController(...[
66+
'model' => $this->model(),
67+
'hasSearch' => $this->search,
68+
'image' => $this->image,
69+
'info' => $this->info ?? false,
70+
'limit' => $this->limit,
71+
'max' => $this->max,
72+
'multiple' => $this->multiple,
73+
'query' => $this->query,
74+
'subpages' => $this->subpages,
75+
'text' => $this->text,
76+
...$this->picker
77+
])
78+
],
8179
'save' => function ($value = null) {
8280
return $this->toStoredValues($value);
8381
},

config/fields/textarea.php

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

3+
use Kirby\Panel\Controller\Dialog\FilesPickerDialogController;
4+
35
return [
4-
'mixins' => ['filepicker', 'upload'],
6+
'mixins' => ['upload'],
57
'props' => [
68
/**
79
* Unset inherited props
@@ -84,35 +86,34 @@
8486
return trim($value ?? '');
8587
}
8688
],
87-
'api' => function () {
88-
return [
89-
[
90-
'pattern' => 'files',
91-
'action' => function () {
92-
return $this->field()->filepicker([
93-
...$this->field()->files(),
94-
'page' => $this->requestQuery('page'),
95-
'search' => $this->requestQuery('search')
96-
]);
97-
}
98-
],
99-
[
100-
'pattern' => 'upload',
101-
'method' => 'POST',
102-
'action' => function () {
103-
$field = $this->field();
104-
$uploads = $field->uploads();
89+
'api' => fn () => [
90+
[
91+
'pattern' => 'upload',
92+
'method' => 'POST',
93+
'action' => function () {
94+
$field = $this->field();
10595

106-
return $this->field()->upload($this, $uploads, fn ($file, $parent) => [
96+
return $field->upload(
97+
$this,
98+
$field->uploads(),
99+
fn ($file, $parent) => [
107100
'filename' => $file->filename(),
108101
'dragText' => $file->panel()->dragText(
109102
absolute: $field->model()->is($parent) === false
110103
),
111-
]);
112-
}
113-
]
114-
];
115-
},
104+
]
105+
);
106+
}
107+
]
108+
],
109+
'dialogs' => fn () => [
110+
'files' => fn () => new FilesPickerDialogController(...[
111+
'multiple' => false,
112+
...$this->files(),
113+
'model' => $this->model(),
114+
'uploads' => $this->uploads,
115+
])
116+
],
116117
'validations' => [
117118
'minlength',
118119
'maxlength'

0 commit comments

Comments
 (0)