Repository navigation
Kirby 6 support
The plugin now works with Kirby 6 (tested with 6.0.0-beta.2) and Kirby 5. Kirby 6 itself didn't need any code change. The fixes below are needed on both versions.
Breaking changes
- Requires Kirby 5 or 6 and PHP 8.2 or newer (was PHP 7.4). For Kirby 3 and 4, keep using 1.x:
composer require afbora/kirby-template-hooks:^1.2. (ba740a9) - Template hooks now work like core hooks: a value returned by a template hook changes the result of the action, e.g. a
beforehook can return a modified page. Before, return values were ignored. Hooks that return nothing are not affected. (9905fe2) - Files without a template now run
file.default.*hooks, like theirfiles/defaultblueprint. Before, the event name had an empty template (file..update:after). (4e5c3cf)
Fixes
- Updating a file stopped with "TypeError: Argument #2 ($input) must be of type array, null given" (fixes #7). Template hooks now get the arguments of the core hook unchanged, so a wrong argument name in the plugin can't break core actions anymore. (9ab919f)
- Duplicating a page stopped with "Argument #2 ($input) must be of type array, string given". (9ab919f)
- Changing a page to unlisted stopped with "Argument #2 ($num) must be of type int, null given". (9ab919f)
- Template hooks got fewer arguments than the core hooks, e.g.
languageCodeforupdate,languageforchangeTitleandchangeSlug, andextensionforfile.changeName. They now get all of them, with the same names as in the hooks reference. (9ab919f)
New
- User role hooks:
user.ROLE.ACTION:before/after, e.g.user.editor.update:after, for all user actions. (fbc10e7) page.TEMPLATE.moveandfile.TEMPLATE.changeTemplatehooks. (b33e43d)changeTemplateandchangeRolerun thebeforehook for the old template or role and theafterhook for the new one.
Changes
composer.jsonno longer has aversionfield, so the git tag is the only version source. (0d4fb87)composer.jsonhasextra.kirby.compatible: ^5.0 || ^6.0and the keywordskirby5andkirby6(waskirby-3andkirby3-plugin).minimum-stabilityandprefer-stableare removed, because they only apply when the plugin itself is the root package. (ba740a9, d19a0c8)- The README lists all actions and explains the arguments, return values and template names. (9ef6c38, 45363dc)
- PHPUnit tests for every page, file and user action, and a GitHub Actions workflow that runs them on Kirby 5.0.0, the latest 5.x and 6.x, with PHP 8.2 to 8.5. (7763749, c1b697e)
.gitattributeskeeps the tests and CI files out of the Composer package. (a8efff7)
Tested with
- Kirby 6.0.0-beta.2 on PHP 8.3, 8.4 and 8.5, Kirby 5.6.2 on PHP 8.2, 8.4 and 8.5, and Kirby 5.0.0 on PHP 8.2.
- Every page, file and user action, before and after, with and without template hooks. The template hooks get exactly the same arguments as the core hooks.
- Multi-language sites:
languageCodeandlanguageforupdate,changeTitleandchangeSlug. - Return values from
beforeandafterhooks, and a template hook that runs the same action again. page.renderhooks are not touched.