Skip to content

2.0.0

Latest

Choose a tag to compare

@afbora afbora released this 01 Nov 19:30
45363dc

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 before hook 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 their files/default blueprint. 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. languageCode for update, language for changeTitle and changeSlug, and extension for file.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.move and file.TEMPLATE.changeTemplate hooks. (b33e43d)
  • changeTemplate and changeRole run the before hook for the old template or role and the after hook for the new one.

Changes

  • composer.json no longer has a version field, so the git tag is the only version source. (0d4fb87)
  • composer.json has extra.kirby.compatible: ^5.0 || ^6.0 and the keywords kirby5 and kirby6 (was kirby-3 and kirby3-plugin). minimum-stability and prefer-stable are 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)
  • .gitattributes keeps 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: languageCode and language for update, changeTitle and changeSlug.
  • Return values from before and after hooks, and a template hook that runs the same action again.
  • page.render hooks are not touched.