Hi,
I want to create a programmable user blueprint. As soon as I am including the following code in my plugin, I get the following error message. Do I have to change something in the plugin index.php to make this work? I also tried to just return a string in the test.php but it seems to be a problem with the index.php.
<?php
use Kirby\Cms\App as Kirby;
Kirby::plugin('cookbook/programmable-userpage', [
'blueprints' => [
'users/test' => function ($kirby) {
return include __DIR__ . '/blueprints/users/test.php';
},
]
]);
Kirby\Cms\Role::load(): Argument #1 ($file) must be of type string, Closure given, called in C:\MAMP\htdocs\kinesiotree\kirby\src\Cms\Roles.php on line 111
When I create the test.yml file manually the userrole gets loaded, it seems to be a problem how I
define the user role in the index.php in the plugin of the programmable blueprint.
Edit:
Creating it like this seems to work, so it’s a problem with the include of the test.php:
<?php
use Kirby\Cms\App as Kirby;
Kirby::plugin('cookbook/programmable-userpage', [
'blueprints' => [
'users/test' => [
"name" => "Test",
"title" => "Test"
]
]
]);
I tired another version and get the same error as above:
Kirby::plugin('cookbook/programmable-userpage', [
'blueprints' => [
'users/test' => function () {
if (($user = kirby()->user()) && $user->isAdmin()) {
return [
'title' => 'Test',
'name' => 'Test',
];
} else {
return [
'title' => 'Test2',
'name' => 'Test2',
];
}
},
]
]);
Screenshot of the error message:
This really looks like a bug. The anonymous function returns a closure and the load function in line 111 ind Roles.php needs a string as parameter.
Anyone knows if this is a bug or how this can work?
Edit:
I got it work. I used this. Seems like a workaround though. This is how I used it
<?php
use Kirby\Cms\App as Kirby;
Kirby::plugin('cookbook/programmable-blueprints', [
'blueprints' => [
'users/test' => (function ($kirby) {
return include __DIR__ . '/blueprints/users/test.php';
})(kirby()),
]
]);
Thanks!
Markus