Hook - feedback


I want to create my own validation for images. With the v2.1 we got hooks - great.
I played with that, but it is a little bit strange to handle. Because a output throw all the time an js error.


kirby()->hook('panel.file.upload', function($page) {
a::show($page); });

How works that? Exists for that a description? I found only that one http://getkirby.com/changelog/kirby-2-1-0

Best David

The context where that hook is triggered:

  if($file = $upload->file()) {
      try {
        $this->checkUpload($file, $blueprint);
        kirby()->trigger('panel.file.upload', $file);
        return response::success('success');
      } catch(Exception $e) {
        return response::error($e->getMessage());
    } else {
      return response::error($upload->error()->getMessage());

As you said you want to create your own validation, Iā€™d say you need to throw an error by throw new Exception('your error message'); within your hook function. And if all is valid, do nothing.

BTW - You might be totally aware of that, but just in case you are not: your hook function gets the $file not $page for this type of hook (panel.file.upload).

1 Like