Skip to content

Improvement - Theme hook only_pages#19146

Closed
lusimeon wants to merge 2 commits into
PrestaShop:developfrom
lusimeon:feature/theme-hook-only-pages
Closed

Improvement - Theme hook only_pages#19146
lusimeon wants to merge 2 commits into
PrestaShop:developfrom
lusimeon:feature/theme-hook-only-pages

Conversation

@lusimeon
Copy link
Copy Markdown

@lusimeon lusimeon commented May 14, 2020

Questions Answers
Branch? develop
Description? In contrast to except_pages sequences in theme.yml who's not very handy, this PR add the posibility to limit hooks to load only on specified pages thanks to an "only_pages" sequence.
except_pages continue to work but if only_pages and except_pages are set on the same hook, only_pages has priority.
Type? improvement
Category? FO
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #16420.
How to test? Run tests, or add only_pages sequence in theme.yml

This change is Reviewable

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.
@lusimeon lusimeon requested a review from a team as a code owner May 14, 2020 20:07
@prestonBot
Copy link
Copy Markdown
Collaborator

Hello @lusimeon!

This is your first pull request on the PrestaShop project. Thank you, and welcome to this Open Source community!

@prestonBot prestonBot added develop Branch Improvement Type: Improvement labels May 14, 2020
@Progi1984
Copy link
Copy Markdown
Member

@lusimeon It seems that your PR broke unit tests : https://travis-ci.com/github/PrestaShop/PrestaShop/jobs/334202032#L524

Copy link
Copy Markdown
Member

@Progi1984 Progi1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests are broken

See commit #da85498a9d for more details.
@lusimeon lusimeon force-pushed the feature/theme-hook-only-pages branch from f01cea3 to 1251548 Compare May 18, 2020 09:47
Comment thread classes/Dispatcher.php
@matks
Copy link
Copy Markdown
Contributor

matks commented May 18, 2020

@lusimeon Nice work !

So you decided to use only_pages data and then compare it to the list of all FO controllers to be able to compute a complete except_pages map, is that right ?

I think if we merge this (and it looks like a nice idea) we need to update the documentation

Copy link
Copy Markdown
Contributor

@Matt75 Matt75 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions

Comment thread classes/Dispatcher.php
if (!empty($extra_data['only_pages'])) {
$extra_data['except_pages'] = [];

$controllersNames = Dispatcher::getControllersNames(_PS_FRONT_CONTROLLER_DIR_);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should add ModuleFrontController too 🤔
Because some module controllers are important like for a blog module or discounted product listing for example

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I will add modules front controllers too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

@micka-fdz
Copy link
Copy Markdown
Contributor

I think it would be a good improvement! Good job @lusimeon

Copy link
Copy Markdown
Contributor

@sowbiba sowbiba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems good to me, waiting for the modification suggested by @Matt75

Copy link
Copy Markdown
Contributor

@matthieu-rolland matthieu-rolland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @lusimeon, lgtm !

We'll wait your implementation of @Matt75 's suggestion before sending this PR to QA.

@kpodemski
Copy link
Copy Markdown
Contributor

Great idea!

@Progi1984 Progi1984 added the Waiting for author Status: action required, waiting for author feedback label May 27, 2020
@lusimeon
Copy link
Copy Markdown
Author

@lusimeon Nice work !

So you decided to use only_pages data and then compare it to the list of all FO controllers to be able to compute a complete except_pages map, is that right ?

I think if we merge this (and it looks like a nice idea) we need to update the documentation

@matks You're right, I'll do it when this PR will be merged. Am I right?

@lusimeon
Copy link
Copy Markdown
Author

Hi, any news on this one? cc @Matt75 @matks

@PierreRambaud PierreRambaud requested a review from matks January 21, 2021 14:38
@PierreRambaud PierreRambaud added the Waiting for dev Status: action required, waiting for tech feedback label Jan 21, 2021
@PierreRambaud
Copy link
Copy Markdown
Contributor

Hi, any news on this one? cc @Matt75 @matks

Little reminder guys :)

@PierreRambaud
Copy link
Copy Markdown
Contributor

Hi, any news on this one? cc @Matt75 @matks

Little reminder guys :)

Ping!

@PierreRambaud PierreRambaud removed the Waiting for author Status: action required, waiting for author feedback label Nov 15, 2021
@Matt75
Copy link
Copy Markdown
Contributor

Matt75 commented Nov 15, 2021

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
At module installation, PrestaShop will automatically register them to Meta table : https://github.com/PrestaShop/PrestaShop/blob/1.7.8.1/classes/module/Module.php#L2970
So controllers will be available in BO > Shop Parameters > Traffic & SEO to manage URL Rewriting for example.
So you can retrieve list of ModuleFrontController thanks to ps_meta table

About ModuleAdminController, it's required to be registered in ps_tab table

@matks matks added Waiting for author Status: action required, waiting for author feedback and removed Waiting for dev Status: action required, waiting for tech feedback labels Nov 17, 2021
@PierreRambaud
Copy link
Copy Markdown
Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

develop Branch Improvement Type: Improvement Waiting for author Status: action required, waiting for author feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Theme.yml - Hooks configuration, alternative to except_pages

10 participants