Skip to content

Commit

Permalink
Merge pull request #1899 from matks/merge-add-hook-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kpodemski authored Dec 9, 2024
2 parents 09e125c + 8fadbc8 commit 018a0ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
21 changes: 2 additions & 19 deletions contribute/contribute-pull-requests/add_hook.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
---
title: Adding a new hook
weight: 3
layout: redirect
redirect: /8/development/components/hook/register-new-hook/
---

# How to add a new Hook
Adding a new hook is a process that can be done in only three steps.

## 1) Add a call to Hook::exec()

As visible in [this PR](https://github.com/PrestaShop/PrestaShop/pull/34431/files), the first step is to add a `Hook::exec()` in the code where you want to execute it. This will execute the code from the modules hooked into your `Hook`.

## 2) Modify the hook.xml file

The second step is correctly adding the `Hook` during installation. You need to add it to the `hook.xml` file, as seen in this [PR](https://github.com/PrestaShop/PrestaShop/pull/34431/files). This will ensure that the `Hook` is added to the database, which enables users to sort modules hooked into it. It won't be possible without the hook in the database.

## 3) Add the new hook in the Autoupgrade fixture

The last step is to make this new hook available for users upgrading from older versions of PrestaShop. You need to add it to the current version of the SQL script of the Autoupgrade module, as can be seen in this [PR](https://github.com/PrestaShop/autoupgrade/pull/672/files).

If you are unsure which file to put the code inside the [autoupgrade module](https://github.com/PrestaShop/autoupgrade), feel free to ping `@PrestaShop/Committers`.

You can also use a [helper](https://github.com/PrestaShop/autoupgrade/pull/577/files) available to add a new hook during the upgrade process for a given version.
3 changes: 2 additions & 1 deletion development/components/hook/register-new-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ INSERT IGNORE INTO `PREFIX_hook` (`name`, `title`, `description`) VALUES
('actionMaintenancePageFormSave', 'Processing Maintenance page form', 'This hook is called when the Maintenance Page form is processed');
```

You can also use a [helper](https://github.com/PrestaShop/autoupgrade/pull/577/files) available to add a new hook during the upgrade process for a given version.

If you wish to test your changes, follow [this page][autoupgrade-install] to install the autoupgrade module.

[example-pr-add-hook-xml]: https://github.com/PrestaShop/PrestaShop/pull/34431/files#diff-83f4085b0cf6d3684a214fdffee7ec16b2f967d60a2674a7d4a536a2898eee26
[autoupgrade-install]: {{< ref "/8/basics/keeping-up-to-date/use-autoupgrade-module.md" >}}

0 comments on commit 018a0ea

Please sign in to comment.