Improvement - Theme hook only_pages#19146
Conversation
In contrast to except_pages sequences in theme.yml who's not very handy, this commit add the posibility to limit hooks to load only on specified pages.
|
Hello @lusimeon! This is your first pull request on the PrestaShop project. Thank you, and welcome to this Open Source community! |
|
@lusimeon It seems that your PR broke unit tests : https://travis-ci.com/github/PrestaShop/PrestaShop/jobs/334202032#L524 |
See commit #da85498a9d for more details.
f01cea3 to
1251548
Compare
|
@lusimeon Nice work ! So you decided to use I think if we merge this (and it looks like a nice idea) we need to update the documentation |
| if (!empty($extra_data['only_pages'])) { | ||
| $extra_data['except_pages'] = []; | ||
|
|
||
| $controllersNames = Dispatcher::getControllersNames(_PS_FRONT_CONTROLLER_DIR_); |
There was a problem hiding this comment.
Maybe you should add ModuleFrontController too 🤔
Because some module controllers are important like for a blog module or discounted product listing for example
There was a problem hiding this comment.
You're right, I will add modules front controllers too.
There was a problem hiding this comment.
After few research, at this time except_pages seems to don't works with all module controllers because some of thoses don't have controller_name or php_self (see classes/Hook.php line 858) attributes set (eg: module ps_emailsubscription/controllers/front/verification.php results in module-ps_emailsubscription- key).
I think an issue need to be open to fix module controller name to have something even (maybe #19226) before we can include module controller in this PR.
@Matt75 If you have any suggestions on how to get all modules controllers names? I tried with filenames return by Dispatcher::getModuleControllers() but it doesn't works when checking permissions in Hook::exec().
|
I think it would be a good improvement! Good job @lusimeon |
|
Great idea! |
@matks You're right, I'll do it when this PR will be merged. Am I right? |
|
Hello @lusimeon Good practices for ModuleFrontController is to be declared by developers in their module class : https://github.com/PrestaShop/PrestaShop/blob/1.7.8.1/classes/module/Module.php#L124 About ModuleAdminController, it's required to be registered in ps_tab table |
|
Hi @lusimeon , Since we had no news from you for more than 30 days, I'll close this pull request. Feel free to reopen or open another one if you think it's still relevant. Thanks! |
except_pages continue to work but if only_pages and except_pages are set on the same hook, only_pages has priority.
This change is