k3-maxpixels-option
k3-maxpixels-option copied to clipboard
Images are not resized on "replace"
When replacing an image in the files section it is uploaded in the original size.
thanks for the issue.
The latest version should now resize images that are uploaded via replace from the file section dropdown menu.
However, files replaced from inside the "File View" still don't get resized. I'm not sure I can do something about this, because I don't think I can change stuff on that view.
I have to research this further.
Nice, it works.
Unfortunately there's no easy access to views yet. I use a hacky way via router to change methods in the views:
this.$router.options.routes.find(route => route.name === "PageFile").component
There are several different File Views: SiteFile, PageFile, UserFile (Names from here: https://github.com/getkirby/kirby/blob/master/panel/src/config/routes.js)
Thanks for info. Globally registering the views is now considered for the 3.2 milestone :), which is scheduled for June 11. https://github.com/getkirby/kirby/issues/1742
We also need to get the max pixels option into the File View, therefore it can't stay in the files section (a file might belong "to many sections").
My idea would be to move the option from the section into the file blueprints.
However to transfer the value from the server to the client I either have to make an extra api request to a custom endpoint, or change the response for the current endpoint. Imho, the cleanest way to alter the current api response, would be the ability to edit API models, like described here: https://github.com/getkirby/ideas/issues/275
If you think the same, upvote that issue :)
I like the idea and it is one way to do it.
Extending the Section itself could be another way. I changed the accept property to an array. It seems to be used in the upload property only, therefore there a small change aswell.
<?php
use Kirby\Cms\File;
$base = require kirby()->root('kirby') . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'sections' . DIRECTORY_SEPARATOR . 'files.php';
Kirby::plugin('rasteiner/k3-maxpixels-option', [
'sections' => [
'files' => array_replace_recursive($base, [
'computed' => [
'accept' => function () {
if ($this->template) {
$file = new File([
'filename' => 'tmp',
'template' => $this->template
]);
return $file->blueprint()->accept();
}
return null;
},
'upload' => function () {
if ($this->isFull() === true) {
return false;
}
// count all uploaded files
$total = count($this->data);
$max = $this->max ? $this->max - $total : null;
if ($this->max && $total === $this->max - 1) {
$multiple = false;
} else {
$multiple = true;
}
return [
'accept' => $this->accept['mime'] ?? '*',
'multiple' => $multiple,
'max' => $max,
'api' => $this->parent->apiUrl(true) . '/files',
'attributes' => array_filter([
'template' => $this->template
])
];
}
]
])
]
]);
updated: function() {
this.$nextTick(() => {
if(this.$refs.upload) {
this.$refs.upload.maxpixels = this.options.accept.maxpixels
}
})
}
and I just realized that accept is not fetched in the FileView sigh...
It took me a while to understand what you mean. I agree, the model is the only clean way in to the File View.