New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues when creating new module for PS 1.7.6 #13490
Comments
@matks let me know what you think about problems and solutions. Maybe you have some other suggestions? |
AFAIK @sarjon was asked to document that in august, 2018
It's part of form theming improvement initiative started by @sarjon (what a man!), we're aware of that since 1.7.3 but we couldn't manage to prioritize this need in 1.7.6 branch... it's not too late, though as this is clearly a bug for me.
I'm not really in favor of using a php hook for rendering while the Form component already provides Form theming system, templates overriding and all that stuff. Sounds like we introduce bad practices to avoid to fix the real issue: the current form theme is incomplete and/or buggy.
Yup, it's a nice idea (see, I'm not ranting about all here 💃 )
Agree, but for me, it's not a flash bag issue but a "worflow" issue. Let's fix it at the root level instead of trying to hack the flashbag object: don't you think? If an exception is raised, the update shouldn't be done at all. And if you catch it in your hook, you should dispatch it after imho. |
if I throw my custom exception |
🏓 @mickaelandrieu 🏓 |
Yes, I prefer let the core transform an exception into a user message. How about create a specific exception for that and an exception listener able to transform the exception (no matter where it's thrown) to a well formatted user message displayed where it's supposed to be displayed? |
I don't think it's possible. What if you have custom use case where |
Do you mean it's impossible to throw an exception in your module with a meaningful message but we should be able to do it populating a flashbag message? In Symfony you can catch specific exception types: // in your module
...
try {
// whatever
} catch(WhateverException $e) {
if (usermessageIsNeeded) {
throw new UserMessageException('What a meaningful message we got, such WOW!');
}
} Then we hook in every environments using an exception listener and catch the UserMessageException exception, and then we populate the flashbag with error messages. It works for this need, it works for every needs: a common need => a common and clean solution 👼 |
Well, that would definitely work, but I could argue about it. 😈 I think that exceptions should not carry user friendly message, but rather technical error that is useful for developer. In case of exception in production, it should be logged for developer and converted into user friendly message depending on exception type/error code. The other reason why exception messages should not be meant for end user is because of translation. If you were to throw exception in your sevice, it would force your service depend on Wdyt? |
THIS We should be able to control user-friendly messages of all types, legacy AdminController was always aware of content of |
Agree 💯 This is why we sent a message for debug, to get information in syslog or anything else, whereas we sent a message to the user to inform him for something he can understand :) |
So right now from your comments I see that there are two possible scenarios:
which one do you guys prefer or do you have more suggestions? 🤔 |
As the 5th item of this bug list has become a topic of debate, I'm going to open 4 other issues for the 4 other items. Discussion can continue about error messages here. EDIT: |
this seems to be better solution |
OK sorry for late answer. Initial issueWhen custom action (= provided by module) fails, with current implementation,
|
Solution we have come up withWe will promote the following ways for modules to dispatch errors: 1) Full control of the error flow
If module wants to display multiple error messages, he can do it using this usecase. 2) Simpler error handling usecase
This is a lot simpler but allows only 1 error message to be displayed. Also we dont expect module developers to translate the ModuleException message so it will probably English. PrestaShop Core will detect that ModuleException has been thrown and check whether the flashbag is empty. If yes, then it will add the ModuleException message into the flashbag. This acts as a fallback to make sure user has at least 1 information message. The previous processing will be performed by a Symfony listener. This will remove the need to perform it in every controller action. @kpodemski @mickaelandrieu How does it look ? |
I would choose number 1 which is Full control of the error flow but I thought about it and realized that some parts just won't work. So here's in my opinion the only possible solution:
@kpodemski @mickaelandrieu @matks @PierreRambaud wdyt? Ofcourse this solution requires to change almost all controller actions which I tried to avoid but I don't see any other way right now. Unless its not a problem in the exception listener clear all the flashbag success messages ( need to test that as well) |
Unless its not a problem in the exception listener clear all the flashbag success messages ( need to test that as well) This is what I thought 🤔actually I did not want us to choose between 1) and 2) : I wanted to say that both solutions will be available to module developers. My idea is just what you said: in Exception listener, when a ModuleException is thrown, check the flashbag. If empty, add the ModuleException message. If not empty, do nothing. We should not mess with the other messages. What usecase are you worrying about 🤔? Someone adding the error in the Flashbag but forget to throw the ModuleException ? Now that I think of it, @jolelievre has worked a lot on modules so his opinion could be helpful too |
Mmmm 🤔now I have doubt as I see that Core/Form/FormHandler has an hookable
while our Core/Form/IdentifiableObject/Handler/FormHandler has not. So the same question that https://github.com/PrestaShop/PrestaShop/pull/14008/files#r288432066 raised appears: should modules be able to:
If yes, then we should go for an |
Im afraid in identifiable object hooks , error messages are handled only on controller level - only the exceptions can be throwed from identifiable object scenario - I thing we should keep the same workflow as it seems more correct then writting to errors array |
Summary
Needs to be done for module release and 1.7.6.0 release
Can be done after module release (as an improvement)
Description
I recently created a sample module which uses CQRS and new hooks in its own system and I found several things which a worth to be investigated and fixed:
Link to the module
https://github.com/friends-of-prestashop/demo-cqrs-hooks-usage-module
Problems
according to this https://github.com/PrestaShop/PrestaShop/blob/develop/tests/Resources/modules/translations/src/Controller/Admin/ExempleController.php#L36
I should be able to have working transaltions from my module controller but they just don't work here https://github.com/friends-of-prestashop/demo-cqrs-hooks-usage-module/blob/master/src/Controller/Admin/CustomerReviewController.php#L54 . But it works in Translations module
for both Translations module and my sample module the translations does not work in main module file as well https://github.com/friends-of-prestashop/demo-cqrs-hooks-usage-module/blob/master/ps_democqrshooksusage.php#L68
I have added
ToggleColumn
in Customers list using the module and it works like a charm.ToggleColumn
required javascript extension added to the gridnew ColumnTogglingExtension()
. To my luck, Customers list has this extension but developers might face the issues when they add column but the list does not have this extension in javascript compiled.Solution:
Currently if I add custom form element to the form it is misaligned and I can't make it look consistent like other elements in the form.
as seen in the image my custom switch is in wrong position and the label is incorrect and if my switch would have a help message it would be impossible to display it. It is due to
form_rest
is rendered and it just adds missing form elements where theform_rest
is used.Solution:
I wish we could make this #13412 appear in 1.7.6 so it will allow us to control rendered html. The only thing the core developers will only need to remember to put
form_rest
inWhen form is submitted and after the main
Customer
form logic is passed the hookhookactionAfterUpdatecustomerFormHandler
is called. InFormHandler
actionBeforeUpdate...
hook has parameterform_data
butactionAfterUpdate
does not have anymore. This forces me to access Request in my hook https://github.com/friends-of-prestashop/demo-cqrs-hooks-usage-module/blob/master/ps_democqrshooksusage.php#L245Solution:
lets just add
form_data
toactionAfter
hooks in form handlersFlashBag
.The problem:
the error happened in module scope but customer data was updated correctly - its weird that both success and error messages are displayed
Solutions:
In module I could extend CustomerException which is being catched in Customer controller but it will lead to 2 error messages : the first will be mine from module while the second be the fallback error message used in the controllers
clearing the flashBag messages from module?
maybe its good after all. Maybe I only need to prefix a message with module name so the client will know that the message has been raised from the module. Maybe even we can automate this by having some kind of Module exception which is caught in certain part of symfony event cycle and it would prepend error, warning, info messages with module names.
The text was updated successfully, but these errors were encountered: