An option to easily register multiple hooks in a module would be great.
I see some options:
public function registerHooks(array $hook_names, $shop_list = null)
{
foreach($hook_names as $hook_name) {
if(! Hook::registerHook($this, $hook_name, $shop_list) )
return false;
}
return true;
}
Or even better if one could also set the hooks the same way as $this->tabs = [] in module construct:
public function __construct()
{
$this->name = 'mymodule';
$this->hooks = ['displayHeader', 'displayFooter'];
}
...and then Module::install() would automatically register those hooks. Also the same for uninstall.
Would be a nice feature.
Thanks for opening this issue! We will help you to keep its state consistent
Hi @onklmaps,
Thanks for your report.
Please in the next time you must follow the template to submit a complete Feature report.
Ping @PrestaShop/product-team @PrestaShop/prestashop-core-developers what do you think of this improvement?
Thank you
Hi,
You're already able to register multiple hooks at once.
https://github.com/PrestaShop/PrestaShop/blob/develop/classes/Hook.php#L563
https://github.com/PrestaShop/ps_facetedsearch/blob/dev/ps_facetedsearch.php#L174
Maybe the documentation needs to be updated.
(https://devdocs.prestashop.com/1.7/development/components/hook/)
Hi @PierreRambaud @onklmaps
This is great 馃槂
Thank you @PululuK!
Hi!
Followup:
I blindly applied this to UNregisterHook(['one', 'two'); but that was not possible. Maybe a good idea that unregisterHook and registerHook has identical features?
Hi!
Followup:
I blindly applied this toUNregisterHook(['one', 'two');but that was not possible. Maybe a good idea that unregisterHook and registerHook has identical features?
@onklmaps This is handled automatically when you uninstall a module
See https://github.com/PrestaShop/PrestaShop/blob/develop/classes/module/Module.php#L710
@PululuK Oh! Another feature I did not know of. And seing how many modules has unregisterHook() in module uninstall, I guess I am not the only one. Thanks for the info 馃憤
Most helpful comment
Hi @PierreRambaud @onklmaps
See https://github.com/PrestaShop/docs/pull/769