This repository was archived by the owner on Jan 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
This repository was archived by the owner on Jan 4, 2021. It is now read-only.
Wildcard hooks (e.g.: page.*:after) #194
Copy link
Copy link
Closed
Description
It would be helpful to be able to have a generic hook to catch all hooks for a particular model class.
For example, I would like to be able to express a generic Page Hook like:
'hooks' => [
'page.*:after' => function ($page, $oldPage) {
},
],
Instead of the more verbose way now:
'hooks' => [
'page.changeNum:after' => function ($page, $oldPage) {
},
'page.changeSlug:after' => function ($page, $oldPage) {
},
'page.changeStatus:after' => function ($page, $oldPage) {
},
'page.changeTemplate:after' => function ($page, $oldPage) {
},
'page.changeTitle:after' => function ($page, $oldPage) {
},
'page.create:after' => function ($page) {
},
'page.delete:after' => function ($status, $oldPage) {
},
'page.update:after' => function ($page, $oldPage) {
},
],
Use Case
Maybe this is a limited and contrived use-case, but I'm making a plugin that clears CDN-based page caches. I want this to occur when any change to a page occurs. In this situation, it's not really important to distinguish between modifications to title, content, template, or num changes. Any change that might affect the content on a page makes it a candidate to invalidate caches.
The main motivation for a catch-all hook would be to avoid potential problems if additional hooks are added in future Kirby versions.
Design Considerations
- The callback might benefit from having a 3rd parameter called
$hookthat would represent the actual hook that is being fired, in case more granular handling is required. - The method of signatures of
page.delete:afteris unique, in that the first parameter is not a Page object. This might be awkward to handle. - There is a silent 2nd parameter of
page.create:after(it's a Page object), but it's not really meaningful.
nilshoerrmann, omz13, REHvision, texnixe, modufolio and 3 more
Metadata
Metadata
Assignees
Labels
No labels