Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dartmoon-io/prestashop-hooks
https://github.com/dartmoon-io/prestashop-hooks
prestashop prestashop-library
Last synced: 26 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/dartmoon-io/prestashop-hooks
- Owner: dartmoon-io
- License: mit
- Created: 2021-06-11T15:32:54.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-21T13:53:42.000Z (over 1 year ago)
- Last Synced: 2024-11-27T21:41:26.447Z (26 days ago)
- Topics: prestashop, prestashop-library
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Prestashop Hooks
PrestaShop hooks done right! Instead of polluting the main file of your module with all the hook definitions, with this package you can define them into their own class.## Installation
1. Install the package
```bash
composer require dartmoon/prestashop-hooks
```2. Add to the main class of your module the trait `HasHookDispatcher` and the `hooks` property
```php
use Dartmoon\Hooks\Traits\HasHookDispatcher;class YourModule
{
use HasHookDispatcher;/**
* Hook classes
*/
protected $hooks = [
//
];// ...
}
```3. Fix the class constructor by initializing the hook dispatcher
```php
public function __construct()
{
//...// Let's init the hook dispatcher
$this->initHookDispatcher();
}
```4. Fix the `install` method to install the hooks
```php
public function install()
{
if (
parent::install()
&& $this->registerHook($this->getHookDispatcher()->getAvailableHooks())
) {
//...return true;
}return false;
}
```## Usage
### Create the hook group class
Let's create the class. For the sake of the example suppose we are creating them inside the `src/Hooks` folder of your module.File `src/Hooks/FrontAssetsHooks.php`
```php
module is the instance of the module
// $this->context is the instance of the current context
}
}
```### Register the hook group class
Put your classes inside the `hooks` property of the main class of your module.```php
use Dartmoon\MyModule\Hooks\FrontAssetsHooks;/**
* Hook classes
*/
protected $hooks = [
FrontAssetsHooks::class
];
```### Reset the module
PrestaShop installs module hooks only at installation time, so you need to reset the module.## License
This project is licensed under the MIT License - see the LICENSE.md file for details