Page 1 of 1

How to attach functionality to hooks ?

Posted: Fri Mar 15, 2019 2:04 am
by MantaPro
I have a feeling I'm overlooking something obvious - sorry

I read with interest the stuff in some module help re. hooks available and in cmsmadesimple.org/documentation/programming/hooks and events

I've used hooks before and Ive added attached functionality to hooks in other CMSs before. The documentation provides examples of how hooks should be built in to a module; I've seen and understand the section on
Using (sending) Hooks which describes \CMSMS\HookManager::do_hook()


but I can't seem to find anything regarding where to put this hook functionality ?. For instance in another CMS, attaching to a hook is always placed in ready.php or init.php in the root directory the CMS is installed in

TIA

Re: How to attach functionality to hooks ?

Posted: Fri Mar 15, 2019 7:58 am
by deactivated010521
I am not sure if you are intrested in the HookManager as programmer or cmsms enduser?

From a programmers perspective read: ./lib/classes/class.HookManager.php to get a sense on what functionality is available.

There are many CMSMS core modules that implement the HookManager for example News: ./modules/News/action.addcategory.php -> NewsCategoryAdded hook. You can also implement the HookManager into your own module actions.

As enduser have a look at /admin -> Extensions -> Event Manager there you can see some in action.

I have to admit the CMSMS (enduser)documentation on the Event Manager is a bit sparse:
https://docs.cmsmadesimple.org/tags/event-manager

These are extensive:
https://docs.cmsmadesimple.org/advanced ... and-events
https://docs.cmsmadesimple.org/advanced/hooks-reference

Re: How to attach functionality to hooks ?

Posted: Sun Mar 17, 2019 3:47 pm
by MantaPro
Thank you for the reply Arnoud

kind of both - it was reading the module help for FEU and the CMSMS Docs section on Hooks & Events that prompted the question. Between those two I wonder if functionality could be added to hooks outside of a Module/ Event - particularly as in these documents the point is made that not all Hooks are Events - i.e. there are Cases which have a have a Hook but no Event

I suppose my use of other CMSs is muddying my understanding (where code snippets (which in CMSMS reside in UDTs and can be triggered via Events), in some other CMSs all hooks can be extended via code snippets added to a particular file in the filesystem (e.g. ready.php etc which is always loaded when the CMS initiates - i.e. outside of the database).

From your reply, with CMSMS hooks are for programmers use within their module; Events are for endusers within their UDTs in Admin. There is no extensibility of hooks outside of a module or UDT

Thanks for the clarification/confirmation Arnoud

Re: How to attach functionality to hooks ?

Posted: Sun Mar 17, 2019 7:34 pm
by calguy1000
You can create a UDT to handle an Event.
That UDT CAN (though it is not a smart idea) emit hooks.

Modules can emit and handle hooks and events.

In the upcoming version of 2.3 everything will be 'hooks' so simple plugins and modules will be able to handle hooks.

No, there is no recommended simple 'php' file you can extend to inject your own php code, other than a module.

Re: How to attach functionality to hooks ?

Posted: Wed Mar 20, 2019 8:15 pm
by MantaPro
Thanks for the update - good to know.

And thanks to you and the rest of the dev Team for all your hard work on CMSMS