I’m working on a Git plugin alternative and need to listen to every page and file hook in order use the correct commit message. The issue is that every time an update is made, the panel.page.sort hook is triggered before panel.page.update and is the one that get it’s message used.
From my research, this is caused because the updateNum() method (which then calls the sort() method) is called before the update hook inside the update() method at panel/app/src/panel/models/page.php.
I understand it’s important to call the updateNum() method there just in case for when the date is being used to order pages. I have quick fix in mind that would not trigger the sort hook on any update, is a pull request welcome?
Another thing that would greatly benefit plugin developer would be to always pass the old and new page object to hooks. When constructing the Page class Kirby could store the old page before updates are applied. Would that be feasible?
Yes, very welcome. Please make sure however that the sort hook is triggered if the sorting number actually changes. And if it doesn’t, it shouldn’t be triggered of course.
The panel.page.move hook already has this feature. It is implemented by cloning the object before modifying it. I agree that the same could be done for the other hooks as well (except for create and delete hooks).
I suggested this not only thinking about my use case, it would allow developer to do any kind of check they need before doing something in the hook. It won’t break existing hooks because the $old object would be the last argument (ignored if not used). Please, let’s do this!