Book Image

PrestaShop Module Development

By : Fabien Serny
Book Image

PrestaShop Module Development

By: Fabien Serny

Overview of this book

Table of Contents (19 chapters)
PrestaShop Module Development
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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', array('object' => $this));
Hook::exec('actionObject'.get_class($this).'AddBefore', array('object' => $this));

The first one is hardcoded and corresponds to a hook, which will be trigged each time a class extending ObjectModel...