Jump to content

How hooking modules works and why is my module hooked to almost everything?


wojwen

Recommended Posts

I'm learning to add and position modules on my site. From what I figured out it works like this: after enabling module it is hooked to two kinds of hooks: actionSomething if it needs to do something when this action is performed or displaySomething to determine where it's displayed. Correct me if I'm wrong.

 

Recently I got a little bit confused because after adding Parallax block module it was displayed on my homepage, but when I wanted to change its position I noticed that it was hooked to many hooks for example: displayHomeBottom, displayHomeTop, displayHomeVeryBottom or displayStBlogLeftColumn. Shouldn't it be hooked to only one of these? If not can you explain me how it works? Are there any tutorials about positioning everything on the site?

Link to comment
Share on other sites

Everything depends on what the module is supposed to do. If this module is something like the Theme Configurator module and allows you to insert different content in various parts of the shop, it may hook to many positions, but not display there if you don't put anything in.

 

Many module authors hook their modules to any hook and allow the shop owner to unhook it. The other approach - hooking to only one supported hook so the shop owner can attach the module to others is rather less common.

Link to comment
Share on other sites

For a module developer, hooks are a difficult thing to guess at because native only has so many hooks, theme developers sometime have many more hooks.  So often times they will not always hook where you really want them, i.e. a hook in a high end theme, this is even more true for responsive, where nav in desktop is not in tablet or mobile.

 

Most 'typical' modules at install usually register  all the hooks they support, really they don't have a much choice, but it just guessing anyway.  Some module developers will then in their module configuration support enable/disable of hooks, better practice than not doing annything and easier to manage than module positions page.

 

I took a new  approach to module hooking, read that shops hook db, filtering out non-positional be and back office hooks etc.  Then you can add one or more hooks to module by device type desktop/tablet/mobile,  because they can and usually have different hook positions.

 

http://screencast.com/t/sOej6GmHUi

 

I show this only to give you idea of what developer faces when working in a hook system, how some some, and how prestaheroes does it.  

 

You should leave installed module hooks alone except where you do not want them to display on you Front of Back office.  Other hooks that you may not think much sense,  and are not displayed are there for 'other' reasons, header = add .css/.js etc, footer maybe to change varirble etc.  You would need to check the actual module hook logic to determine how it's used (unless obvious display) before removing.

 

Happy day, el

Link to comment
Share on other sites

My Image/Video Gallery module installs into every hook it needs and then only displays content in the hooks with blocks configured in the module. It's more user-friendly than requiring the merchant to switch between my module and the Modules > Positions tab all the time.

 

I'm going to guess if you remove the module from the hooks you're not using, the module will no longer work if you try to reconfigure it in the future. Better to leave them alone unless you're sure you won't reconfigure the module.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...