-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
With plugin enabled, onAdminSave event doesn't fire #58
Comments
This is basically because of some plugins seem to break if I used the old events. I think we just need to add a few configuration options for the events. |
Events were added in getgrav/grav@3a05dcf |
I am not sure if this is 100% compatible. The original code: The new: I am not sure, I guess It seems those events are outdated anyways, so can you maybe point us to the new events that are able to modify the page correctly? Also is there an option to query for the grav version to subscribe to different events? |
Already fixed that long time ago: |
Oh, you are right! But what about |
It means that you have replaced the page object in your plugin with another one. You shouldn't do that as it breaks the saving. Instead of doing that, just modify the object before it gets saved. |
Alright, so nothing will break. Thanks a lot for clarifying :-) |
In my plugin I am checking the type of the if (!($page instanceof \Grav\Common\Page\Page)) {
return;
} Now this does not work with the new flexobject. The check is still required, as saving a plugin config also fires this event. But even if I ignore the check for now all page content is cleared on safe. This is possibly because I am modifying the page and this fails. But no error message is displayed this could be improved. I am still searching for a solution. Is there a common way to support Flexpages and "normal/old" Pages? Edit: It seems setting
You can reproduce with: public function onAdminSave(Event $event)
{
$page = $event['object'];
// When saving plugin configurations we should ignore the event
if (!($page instanceof \Grav\Common\Page\Interfaces\PageInterface)) {
return;
}
$header = new Data((array)$page->header());
$page->header($header->toArray());
} The getter of header() returns wrong values, here is a json dump:
Is it possible that the header is now a This is my solution: $header = $page->header();
if (!($header instanceof \Grav\Common\Page\Header)) {
$header = new Data((array)$header);
} |
Yes, check against |
Yeah, but the header is a breaking change that should be noted in the release notes! It is no |
Header class has been there since 2015, but it was not used in the event before (not sure why). You should be using something like: if (!$page instanceof PageInterface) {
return;
}
$header = $page->header();
if (!$header instanceof Header) {
$header = new Header((array)$header);
} The above code should be working starting from Grav 1.6. |
Also added it to changelog. |
Since flex-objects seems to replace the admin plugin's
AdminController
, the events fired there are not fired. So other plugins usingonAdminSave
and/oronAdminAfterSave
won't work anymore.The text was updated successfully, but these errors were encountered: