Skip to content

Commit b806043

Browse files
fix service availability issue
1 parent 4295f87 commit b806043

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

classes/Hook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ private static function getHookModuleFilter()
11301130
}
11311131

11321132
try {
1133-
$hookModuleFilter = $serviceContainer->get('prestashop.hook.module.filter');
1133+
$hookModuleFilter = $serviceContainer->get(HookModuleFilter::class);
11341134
} catch (Exception $e) {
11351135
return null;
11361136
}

config/services/common.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ services:
2626
public: false
2727
tags: ['container.env_var_processor']
2828

29-
prestashop.hook.module.filter:
30-
class: PrestaShop\PrestaShop\Core\Hook\HookModuleFilter
29+
PrestaShop\PrestaShop\Core\Hook\HookModuleFilter:
3130
arguments:
3231
- !tagged core.hook_module_exec_filter

src/Core/Hook/HookModuleFilter.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626

2727
namespace PrestaShop\PrestaShop\Core\Hook;
2828

29+
/**
30+
* This service is responsible for filtering the list of modules for a given hook that is returned by
31+
* the getHookModuleExecList method from Hook.php. It is called at the very end of getHookModuleExecList.
32+
*
33+
* How to use it to filter a list of modules for a hook:
34+
*
35+
* In your module, create a service which implements the HookModuleFilterInterface and give it
36+
* the tag named core.hook_module_exec_filter. Then in your service, you can filter the list of modules
37+
* in the filterHookModuleExecList method, according to your own logic.
38+
*
39+
* Your service will automatically be sent in this class's constructor, and be used to filter the list of modules.
40+
*/
2941
class HookModuleFilter implements HookModuleFilterInterface
3042
{
3143
private $hookModuleFilters;

src/Core/Hook/HookModuleFilterInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
namespace PrestaShop\PrestaShop\Core\Hook;
2828

29+
/**
30+
* This interface must be implemented by all services that will be used by the HookModuleFilter service.
31+
* See HookModuleFilter.php for more explanations.
32+
*/
2933
interface HookModuleFilterInterface
3034
{
3135
public function filterHookModuleExecList(array $modules, string $hookName): array;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
imports:
22
- { resource: ./circuit_breaker.yml }
3+
4+
services:
5+
PrestaShop\PrestaShop\Core\Hook\HookModuleFilter:
6+
arguments:
7+
- !tagged core.hook_module_exec_filter

0 commit comments

Comments
 (0)