Upgrade to 3.1.0
This commit is contained in:
@@ -29,6 +29,21 @@ return [
|
||||
return trim($default);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the options for the files picker
|
||||
*/
|
||||
'files' => function ($files = []) {
|
||||
if (is_string($files) === true) {
|
||||
return ['query' => $files];
|
||||
}
|
||||
|
||||
if (is_array($files) === false) {
|
||||
$files = [];
|
||||
}
|
||||
|
||||
return $files;
|
||||
},
|
||||
|
||||
/**
|
||||
* Maximum number of allowed characters
|
||||
*/
|
||||
@@ -50,10 +65,103 @@ return [
|
||||
return $size;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the upload options for linked files
|
||||
*/
|
||||
'uploads' => function ($uploads = []) {
|
||||
if ($uploads === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_string($uploads) === true) {
|
||||
return ['template' => $uploads];
|
||||
}
|
||||
|
||||
if (is_array($uploads) === false) {
|
||||
$uploads = [];
|
||||
}
|
||||
|
||||
return $uploads;
|
||||
},
|
||||
|
||||
'value' => function (string $value = null) {
|
||||
return trim($value);
|
||||
}
|
||||
],
|
||||
'api' => function () {
|
||||
return [
|
||||
[
|
||||
'pattern' => 'files',
|
||||
'action' => function () {
|
||||
$field = $this->field();
|
||||
$model = $field->model();
|
||||
|
||||
if (empty($filed->files['query']) === false) {
|
||||
$query = $filed->files['query'];
|
||||
} elseif (is_a($model, 'Kirby\Cms\File') === true) {
|
||||
$query = 'file.siblings';
|
||||
} else {
|
||||
$query = $model::CLASS_ALIAS . '.files';
|
||||
}
|
||||
|
||||
$files = $model->query($query, 'Kirby\Cms\Files');
|
||||
$data = [];
|
||||
|
||||
foreach ($files as $index => $file) {
|
||||
$image = $file->panelImage($field->files['image'] ?? []);
|
||||
$model = $field->model();
|
||||
|
||||
$data[] = [
|
||||
'filename' => $file->filename(),
|
||||
'dragText' => $file->dragText(),
|
||||
'image' => $image,
|
||||
'icon' => $file->panelIcon($image)
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'upload',
|
||||
'action' => function () {
|
||||
$field = $this->field();
|
||||
$uploads = $field->uploads();
|
||||
|
||||
if ($uploads === false) {
|
||||
throw new Exception('Uploads are disabled for this field');
|
||||
}
|
||||
|
||||
if ($parentQuery = ($uploads['parent'] ?? null)) {
|
||||
$parent = $field->model()->query($parentQuery);
|
||||
} else {
|
||||
$parent = $field->model();
|
||||
}
|
||||
|
||||
if (is_a($parent, 'Kirby\Cms\File') === true) {
|
||||
$parent = $parent->parent();
|
||||
}
|
||||
|
||||
return $this->upload(function ($source, $filename) use ($field, $parent, $uploads) {
|
||||
$file = $parent->createFile([
|
||||
'source' => $source,
|
||||
'template' => $uploads['template'] ?? null,
|
||||
'filename' => $filename,
|
||||
]);
|
||||
|
||||
if (is_a($file, 'Kirby\Cms\File') === false) {
|
||||
throw new Exception('The file could not be uploaded');
|
||||
}
|
||||
|
||||
return [
|
||||
'filename' => $file->filename(),
|
||||
'dragText' => $file->dragText(),
|
||||
];
|
||||
});
|
||||
}
|
||||
]
|
||||
];
|
||||
},
|
||||
'validations' => [
|
||||
'minlength',
|
||||
'maxlength'
|
||||
|
Reference in New Issue
Block a user