Migrate demoextrafield extra-field validation to Symfony constraints#250
Merged
jolelievre merged 2 commits intoJun 24, 2026
Merged
Conversation
Replace the legacy validator: 'isXxx' strings with constraints: [...] of real Symfony Constraint objects, matching the core constraint-based validation. - video_link (LANG): DefaultLanguage (whole-array) + All([Url]) (per-language) - custom_date (SHOP): Assert\Date - is_dangerous (COMMON, SwitchType): no constraints (validation is opt-in) - hookDisplayFooterProduct loads the product in one language (langId is Product's 3rd ctor arg) and updates date_last_seen plus the per-language video_link only when it is non-empty
d1017bc to
7aa5505
Compare
- Rename the formRequired constructor argument to required, matching the renamed ExtraPropertyDefinition flag (now shared by the BO form and the Admin API). - Drop allowNull on video_link's DefaultLanguage so the whole-array validation is actually exercised: an all-empty submit no longer passes by default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Migrates the
demoextrafieldexample module from the legacy singlevalidator: 'isXxx'string to Symfony Validator constraints (constraints: [...]), matching the core change in PrestaShop/PrestaShop#41806.Each
registerExtraProperty(...)definition now passes realSymfony\Component\Validator\Constraintobjects:video_link(LANG) is the showcase for both multilang validation styles on one field:new DefaultLanguage(allowNull: true, fieldName: 'Video link')— whole-array: if any language is filled, the default language must be too;new Assert\All([new Assert\Url()])— per-language: each language value must be a valid URL.custom_date(SHOP) →new Assert\Date().is_dangerous(COMMON,SwitchType) → no constraints — demonstrates that validation is opt-in (a switch always yields a valid 0/1).date_last_seen(COMMON) stays read-only, auto-updated by the FO hook.hookDisplayFooterProductis updated to load the product in a single language (new Product($productId, false, $languageId)— notelangIdis Product's 3rd ctor argument) and updatedate_last_seen(COMMON) plus, only when it's non-empty, the per-languagevideo_linkviaObjectModel::update()— exercising constraint validation in the front-office legacy container.Depends on
associatedApismigration; this branch is stacked on it and will be rebased ontomasteronce Replace displayApi flag with associatedApis in demoextrafield #249 merges.How to test
demoextrafield; open a product form.Video link: invalid URL in any language → per-language URL error; fill a non-default language but leave the default empty →DefaultLanguageerror; empty everywhere → passes; valid → persists.date_last_seenand (when set) the current language'svideo_link.