feat: model attribute conditions and section conditional visibility#73
feat: model attribute conditions and section conditional visibility#73ManukMinasyan wants to merge 2 commits into3.xfrom
Conversation
Add two new feature-flagged capabilities: 1. Model attribute conditions: visibility conditions can now reference the parent model's database columns (e.g., show field when product.type === 'physical'), not just other custom field values. 2. Section-level visibility: sections support the same conditional visibility system as fields, with full parity for both custom field and model attribute conditions. Key changes: - New ConditionSource enum (CustomField / ModelAttribute) - ModelAttributeDiscoveryService for introspecting model columns - VisibilityData and CoreVisibilityLogicService accept optional Model - FrontendVisibilityService generates $get() paths per source type - SectionComponentFactory applies visibleJs for reactive visibility - VisibilityComponent admin UI with source selector and dynamic inputs - Fix visibleJs/visible() conflict that prevented reactive visibility
There was a problem hiding this comment.
Pull request overview
This pull request introduces two major features for conditional visibility in custom fields: model attribute conditions and section-level visibility, along with a critical fix for reactive visibility on edit forms.
Purpose: Previously, visibility conditions could only reference other custom field values. This PR extends the system to also reference the parent model's database columns (e.g., show field when product.type === 'physical'). Additionally, sections can now have the same conditional visibility as fields, and a server-side rendering bug that prevented reactive visibility has been fixed.
Changes:
- Model attribute conditions: Visibility can now reference parent model database columns via new
ConditionSourceenum andModelAttributeDiscoveryService - Section-level visibility: Full parity with field visibility including both custom field and model attribute conditions
- visibleJs/visible() conflict fix: Removed server-side
visible(false)that preventedvisibleJs()from rendering, enabling reactive visibility on edit forms
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/Enums/ConditionSource.php |
New enum defining CustomField vs ModelAttribute sources |
src/Services/ModelAttributeDiscoveryService.php |
Introspects model columns via Schema facade with caching |
src/Data/VisibilityConditionData.php |
Added source field with backward-compatible default |
src/Data/VisibilityData.php |
Accepts optional Model for attribute evaluation |
src/Data/CustomFieldSectionSettingsData.php |
Added visibility property for sections |
src/Services/Visibility/CoreVisibilityLogicService.php |
Section visibility evaluation support |
src/Services/Visibility/FrontendVisibilityService.php |
JS generation for model attributes vs custom fields |
src/Services/Visibility/BackendVisibilityService.php |
Section visibility checking |
src/Filament/Integration/Factories/SectionComponentFactory.php |
Applies visibleJs without conflicting visible() |
src/Filament/Integration/Base/AbstractFormComponent.php |
Fixed visibleJs/visible() conflict for fields |
src/Filament/Management/Forms/Components/VisibilityComponent.php |
UI for source selection and model attribute inputs |
src/Filament/Management/Schemas/SectionForm.php |
Visibility component in section forms |
src/Filament/Integration/Builders/FormBuilder.php |
Passes record to section factory |
src/Livewire/ManageCustomFieldSection.php |
Slideover mode for wider visibility UI |
src/Filament/Management/Pages/CustomFieldsManagementPage.php |
Slideover mode for section creation |
src/Enums/CustomFieldsFeature.php |
Two new feature flags |
tests/Feature/SectionVisibilityIntegrationTest.php |
49 integration tests covering all scenarios |
tests/Feature/ModelAttributeConditionsTest.php |
Comprehensive unit tests for new features |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Remove redundant _ENABLED suffix for consistency with other SYSTEM_* feature names.
Summary
product.type === 'physical'), not just other custom field valuesvisible(false)was preventingvisibleJs()from ever rendering, breaking reactive visibility on edit formsKey changes
ConditionSourceenum (CustomField/ModelAttribute)ModelAttributeDiscoveryServicefor introspecting model columns viaSchema::getColumns()VisibilityDataandCoreVisibilityLogicServiceaccept optional?Model $recordFrontendVisibilityServicegenerates$get('column')vs$get('custom_fields.code')paths per sourceSectionComponentFactoryappliesvisibleJswithout conflictingvisible()for reactive visibilityVisibilityComponentadmin UI with source selector and dynamic inputs for model attributesSECTION_CONDITIONAL_VISIBILITYenabledNew feature flags
MODEL_ATTRIBUTE_CONDITIONS— enables model attribute source in visibility conditionsSECTION_CONDITIONAL_VISIBILITY— enables visibility conditions on sectionsTest plan
SectionVisibilityIntegrationTestcovers:ModelAttributeConditionsTestcovers ConditionSource enum, ModelAttributeDiscoveryService, VisibilityData with records, mixed conditions, backward compatibility