Skip to content

feat: model attribute conditions and section conditional visibility#73

Open
ManukMinasyan wants to merge 2 commits into3.xfrom
feat/model-attribute-conditions-section-visibility
Open

feat: model attribute conditions and section conditional visibility#73
ManukMinasyan wants to merge 2 commits into3.xfrom
feat/model-attribute-conditions-section-visibility

Conversation

@ManukMinasyan
Copy link
Collaborator

Summary

  • 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
  • Section-level visibility: sections support the same conditional visibility system as fields, with full parity for both custom field and model attribute conditions
  • Fix visibleJs/visible() conflict: server-side visible(false) was preventing visibleJs() from ever rendering, breaking reactive visibility on edit forms

Key changes

  • New ConditionSource enum (CustomField / ModelAttribute)
  • ModelAttributeDiscoveryService for introspecting model columns via Schema::getColumns()
  • VisibilityData and CoreVisibilityLogicService accept optional ?Model $record
  • FrontendVisibilityService generates $get('column') vs $get('custom_fields.code') paths per source
  • SectionComponentFactory applies visibleJs without conflicting visible() for reactive visibility
  • VisibilityComponent admin UI with source selector and dynamic inputs for model attributes
  • Section create/edit uses slideover with larger width when SECTION_CONDITIONAL_VISIBILITY enabled

New feature flags

  • MODEL_ATTRIBUTE_CONDITIONS — enables model attribute source in visibility conditions
  • SECTION_CONDITIONAL_VISIBILITY — enables visibility conditions on sections

Test plan

  • 415 tests passing (366 existing + 49 new)
  • PHPStan clean (0 errors)
  • New SectionVisibilityIntegrationTest covers:
    • SectionComponentFactory applies visibleJs without visible() (model attr, custom field, mixed)
    • Feature flag gating
    • All section types (Section, Fieldset, Headless Grid)
    • JS expression generation for all operators and logic modes
    • Livewire integration (edit page rendering with section conditions)
    • Backend evaluation (ALL/ANY logic, SHOW_WHEN/HIDE_WHEN, mixed conditions)
    • Edge cases (empty conditions, null record, multiple sections, null values)
  • New ModelAttributeConditionsTest covers ConditionSource enum, ModelAttributeDiscoveryService, VisibilityData with records, mixed conditions, backward compatibility

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
Copilot AI review requested due to automatic review settings February 12, 2026 19:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ConditionSource enum and ModelAttributeDiscoveryService
  • 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 prevented visibleJs() 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant