Custom PageModels in KQL

Hi, I’m just starting to use KQL on a new project, in which I use many different blueprints and PageModels.

When doing a query to a page without custom pageModel, I get the expected result:

{
    query: 'site',
    select: {
        title: true
    }
}

But when I do the same query to a page with a custom pageModel, I get the error from the interceptor:

{
    query: 'page("myPage")',
    select: {
        title: true
    }
}

Kirby\Cms\Page::__construct(): Argument #1 ($props) must be of type array, myPageModel given, called in /site/plugins/kql/src/Kql/Interceptor.php on line 254

title is not a mutating method so I expect that it should not be blocked. So I assume the whole model is blocked. I tried to allow it via the config, but that doesn’t help:

return [
	'kql' => [
		'classes' => [
			'allowed' => [
				'myPageModel'
			]
		]
	]
]

I also tried to go through this: Page method is not returning when using Kirby Query Language but I even don’t do it right or don’t properly understand the namespacing-thing it or it’s not up to date with version 2…

The error persists. How can I solve that?

Thank you!

PS: I use ~20 different pageModels, so it would be nice to have the “allowance” to be as simple as possible :slight_smile: and it’s also not really an option to get rid of the pageModels.

I now solved it by registering all my custom PageModels under the Kirby\Cms namespace. It then didn’t‘t even need the allowance.

// site/plugins/my-plugin/MyPageModel.php

namespace Kirby\Cms;
class MyPageModel extends Page {}
// site/plugins/my-plugin/index.php

use Kirby\Cms\App as Kirby;
require_once __DIR__ . '/MyPageModel.php';

Kirby::plugin('me/my-plugin', [
	'pageModels' => [
		'myPage' => 'Kirby\Cms\MyPageModel',
	],
]);

Not sure if it’s a good solution, but it works :slight_smile:

Thanks a lot @moritzebeling for this workaround! I just ran into the same problem, having outsourced page models into another namespace.

This fixed my usecase, although I’m not sure why KQL denies the custom class, even if I allow it via the kql.classes.allowed option.