The dynamic hooks
As you saw in the previous part and in the PrestaShop source code, when a hook is called, the hook name is generally hardcoded. For example, this hook call will always be used to display something on the left column:
Hook::exec('displayLeftColumn');
However, you will find that in some part of the software, there are hooks whose names are constructed dynamically. You will find them in abstract classes such as ObjectModel
and AdminController
, or admin helper templates such as form.tpl
and view.tpl
.
Let's take the ObjectModel
class (/classes/ObjectModel.php
) as an example. If we search for the first Hook::exec
method in the file, we will find the following two hooks, one beside the other at the beginning of the add
method:
Hook::exec('actionObjectAddBefore', ...
Get PrestaShop Module Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.