Form validation in Shopware 6 administration

Does anybody know of a good tutorial on how to implement form validation in a custom module in the Shopware 6 administration? The “how to’s” that I found go into the details of crud actions, but without any reference to validations. As a newbe to Shopware 6 programming, the existing Shopware 6 administration modules unfortunately are a bridge too far at this point in my learning curve ;-) 

Thanks for your help!

1 „Gefällt mir“

Hi, could you get a solution for that problem? I run into the same issue

The validation currently pretty sucks. 

Anyway just take a look at mapApiErrors and you get the idea.

https://github.com/shopware/platform/blob/4bdbc9238e57f6cd3e33fc97a16aaa1e5d19d15a/src/Administration/Resources/app/administration/src/app/component/rule/condition-type/sw-condition-line-item-custom-field/index.js#L5

or better mapPropertyErrors  

https://github.com/shopware/platform/blob/87fc9e8cf4cdab0650e0caaf9a8ba12bab2902c2/src/Administration/Resources/app/administration/src/module/sw-customer/component/sw-customer-address-form/index.js

Don’t forget to add a Required flag within your Entity etc.

3 „Gefällt mir“

Thanks ShapeAndShift,

This brought me one step closer to implementing form validations in the backend. I do wonder though how to tie the validations into an entity’s API. Take customer as an example:

I see a lot of validation factories in platform/src/Core/Checkout/Customer/Validation at 4bdbc9238e57f6cd3e33fc97a16aaa1e5d19d15a · shopware/platform · GitHub which are injected through platform/customer.xml at 4bdbc9238e57f6cd3e33fc97a16aaa1e5d19d15a · shopware/platform · GitHub

(BTW it looks like this has changed from my SW6 developer version, which defines e.g. an account service in customer.xml that mentions a validation factory).

A tutorial that describes what I need to define where in this context as per the latest SW6 programming guidelines would really help!

Thanks, Pieter

@Pieter schrieb:

A tutorial that describes what I need to define where in this context as per the latest SW6 programming guidelines would really help!

Thanks, Pieter

Hi, is there meanwhile a tutorial available?