Files
File Blueprint
Like the page blueprint, you can add the gates to a file blueprint to define which permissions a member needs to access that file.
site/blueprints/files/default.yml
title: Default Files Blueprint
fields:
gates:
extends: fields/gates/plans
# or extends: fields/klub/gates/plans
Checking Gates in PHP
Most of the time you will want to remove those files or images from collections the member cannot access. You can do that with the removeNotAllowed()
-FilesMethod provided by the Klub plugin.
foreach ($page->images()->removeNotAllowed() as $image) {
// ...
}
Alternatively, you could use the *->allows()
-helpers to check a given file directly.
if (klub()->allows(kirby()->user(), $file->gates())) {
// ...
}
if ($file->isAllowed()) {
// ...
}
if ($file->isNotAllowed()) {
// ...
}