luya-module-cms
luya-module-cms copied to clipboard
Hook::on in Block with enabled cache
If you use the Hook::on
function in a block with cache enabled it only works once (after cache clear).
Currently I invoke the function in the view file, is there a possibility to exclude certain functions in the block from caching?
Maybe we can have an event listener which is triggered accordingly (whether its register from cache or not):
$this->on(self::EVENT_AFTER_REGISTER, function() { // do your stuff });
@boehsermoe onRegister() and onRegisterFromCache() should trigger an event which blocks can register listeneres while initialize (init() method) (example above)
Ok I will take a closer look at the next days.
i think $this->trigger(self::EVENT_ON_REGISTER) should do the job, maybe i will find time next week.
I think it is a little more difficult. For one the block classes does not have any event handling implemented yet. The other thing is if you override a view from a core block (or other module) you cannot listen on this event without make your own block. It should be able to listen on events via block variants too. What do you think?
The event handling can be achieved by using Component instead of BaseObject for InternalBaseBlock. I think this is just a more wide used behavior when registering hooks (or other things) inside a block, therefore this event is used.