getkirby-v2 / panel

This is the deprecated admin panel for Kirby v2.
http://getkirby.com
Other
133 stars 71 forks source link

Pre hook that runs before content is saved #1116

Closed jenstornell closed 3 years ago

jenstornell commented 6 years ago

I thought there was an issue about it but it seems like it's not.

Hook before save

A hook that runs before save would be helpful in situations where the content needs to be manipulated before save.

If we use for example an update hook, it would write the file and then run the hook that will write to the file again. It will write to the file two times on each save.

A real case is this issue

https://github.com/Addpixel/KirbyComments/issues/35

In short, I want to flatten a nested structure before the content is saved.

Maybe it should be called pre-hook or perhaps panel-filter. I think panel filter is better.

lukasbestle commented 6 years ago

If I understand your use-case correctly, you want to overwrite the way the plugin stores custom fields by running your code after the plugin's code has been run. I'm not so sure about this as that's a hack.

jenstornell commented 6 years ago

Every time we need to manipulate the data, there is no reason to save the file two times. Instead, it would be better if the manipulation would occur before the save, similar to a filter.

Hooks are good to use as triggers. Filters are good to use for preparing the data before the save.

It would happen in this order:

  1. Click the Panel save.
  2. Run filters.
  3. Saves the content to file.
  4. Run hooks.

But because there already are filters, maybe there is a better name for it.

lukasbestle commented 6 years ago

Makes sense. :)