Hi everyone
While testing Kirby 5 (currently beta 2), I encountered an issue where the panel’s site translation for all secondary languages stops working when using site()
. This happened, for example, in a panel plugin where I conditionally load blueprints based on user roles:
$blueprintSite = __DIR__ . '/blueprints/editor.yml';
if (site()->userIs('admin')) {
$blueprintSite = __DIR__ . '/blueprints/admin.yml';
}
use Kirby\Cms\App;
App::plugin('grommasdietz/gd-site-blueprint', [
'blueprints' => [
'site' => $blueprintSite,
],
]);
I fixed this by switching to kirby()
instead of site()
:
if ($user = kirby()->user()) {
if ($user->role() == 'admin') {
$blueprintSite = __DIR__ . '/blueprints/admin.yml';
}
}
I noticed the same problem e.g. on this plugin for a virtual home page:
use Kirby\Cms\App;
use Kirby\Cms\Page;
use Kirby\Uuid\Uuid;
load([
'HomePage' => 'models/HomePage.php',
], __DIR__);
App::plugin('grommasdietz/gd-virtual-homepage', [
'pageModels' => [
'home' => HomePage::class
],
'pages' => [
'home' => new Page([
'slug' => 'home',
'template' => 'home',
'content' => [
'title' => site()->title(), // conflicting, works without
'uuid' => Uuid::generate(),
]
])
],
]);
The issue seems to be related to the use of site()
in a multi-language setup:
- Instead of rendering translated fields for secondary languages, the content always falls back to the default language.
- Removing
site()
resolves the conflict, but it’s not ideal.
I’ve briefly checked the changelog but couldn’t find any reason for this behavior. Could this be a regression? If so, I’m happy to create a GitHub bug report.