fix: Add support for dependsOn inside flexible content fields #547
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.
Summary
This PR adds proper support for Nova's
dependsOnfunctionality inside flexible content layouts by introducing a new middleware that transforms field names in dependent field requests.Problem
When using
dependsOnon fields inside a Flexible layout, the callbacks don't receive the expected field names. This is because:ckOi67sYIRR0L6kh__product)creation-fieldsorupdate-fieldsendpoints for dependent fields, it sends these prefixed namesdependsOncallback expects the original field names (e.g.,product)Solution
Added a new middleware
InterceptFlexibleDependsOnAttributesthat:creation-fieldsandupdate-fields)fieldquery parameter by stripping the group prefixThis allows the
dependsOncallbacks to work correctly inside flexible layouts.Usage Example
Files Changed
src/Http/Middleware/InterceptFlexibleDependsOnAttributes.php- New middleware for handling dependsOn requestssrc/FieldServiceProvider.php- Register the new middlewareTechnical Details
The middleware uses the existing
FlexibleAttribute::GROUP_SEPARATORconstant (__) to detect and strip group prefixes from field names. It only processes requests that match Nova's dependent field API routes.Fixes #524