Creating a programmable user blueprint fails

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

I think it’s probably a missing feature, because the closure is not accepted. To me, it seems as if the callback feature is yet not implemented for user blueprints.

Yes seems like it’s the feature “programmable user blueprint” missing.

I wanted to edit one blueprint for user and admin. But as soon as I change the blueprint in the php file, it’ll end up as user with “nobody” as role. So yeah seems like the feature of two different views for one role is missing.

I added a feature request, maybe it’ll be added in the future.