Closed hdodov closed 5 years ago
I double-checked and this isn't really a bug, but the way the API handles languages.
$site->translation()
"listens" to the currently active language. The currently active language is set with $kirby->setCurrentLanguage('bg');
The API only sets the currently active language if it finds a "x-language" header. In your manual API call example, the header is not set. That means that English is still the active language.
Describe the bug I've developed a plugin that uses the
site.update.after
hook. It works as expected from within the panel, but does not when the site is updated via the API.If the panel calls the hook, the
site.update.after
callback gets the correct translation - if you update the default language data, you get the English$page
. If you update a translation, you get that translation's$page
(Bulgarian in my case). However, if the hook is triggered by the API:You always get the English translation.
To Reproduce Steps to reproduce the behavior:
Add a new language. For example, Bulgarian (code
bg)
.Open the panel and edit something in the Site in the Bulgarian translation.
You should get an error in the panel:
That's because of the
var_dump()
in the hook. The response would no longer be valid JSON. You should inspect that response in the Network tab of your DevTools. There, the result of thatvar_dump()
should bebg
, as expected, because you're editing the Bulgarian translation of the page.testUpdate
route of the API:var_dump()
will been
instead ofbg
.Expected behavior The hook should receive the correct translation when triggered by the API.
Kirby Version 3.1.0
Desktop (please complete the following information):