feat: consumer hooks to scope field uniqueness + visibility picker#175
Merged
ManukMinasyan merged 1 commit intoJun 27, 2026
Merged
Conversation
38b2074 to
4661824
Compare
Field-name uniqueness and the conditional-visibility 'depends on' picker are scoped entity-type-wide. Consumers that build multiple forms on one entity type (e.g. a versioned form builder) need to reuse field names/sections across forms. Add two opt-in, no-op-by-default hooks mirroring the existing section pattern: - FieldForm::resolveUniqueRuleModifierUsing() scopes the name uniqueness rule - VisibilityComponent::resolveAvailableFieldsScopeUsing() scopes the field picker make()/makeForSection()/schema() gain an optional CustomFieldSection passed by the management Livewire components. Code uniqueness stays global. Also brings three pre-existing files into compliance with the newer rector (unused imports) so the suite is green.
4661824 to
dcada94
Compare
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.
Summary
Adds two opt-in consumer hooks so an application can scope custom-field management to a subset of an entity's fields, instead of the package's default "all fields are global per
entity_type" behaviour. Both hooks are strict no-ops when not registered, so existing consumers are unaffected.This is needed by consumers that build multiple separate forms on one entity type (e.g. a versioned form builder), where the same field names/sections are intentionally reused across forms. Today such consumers hit two problems:
The section-level analog of (1) already had a hook (
ManageCustomFieldSection::resolveUniqueRuleModifierUsing+SectionForm::modifyUniqueRuleUsing). This PR adds the matching field-level hook and a visibility-picker scope hook.What's added
FieldForm::resolveUniqueRuleModifierUsing(?Closure)— register a resolverfn (?CustomFieldSection $section): ?Closurethat returns aUniquerule modifier (ornull). Applied to the name uniqueness rule only (code remains globally unique, consistent with the package's code-based field resolution).FieldForm::schema()gains an optional?CustomFieldSection $sectionparam, passed byManageCustomField::editAction()(the edited field's section) andManageCustomFieldSection::createFieldAction()(the create-target section).VisibilityComponent::resolveAvailableFieldsScopeUsing(?Closure)— register a resolverfn (string $entityType, ?CustomFieldSection $section): ?Closurethat returns a query constraint (ornull) applied togetAvailableFields().make()/makeForSection()gain an optional?CustomFieldSectionso the field/section being edited can be passed through (FieldForm→ field-level conditions,SectionForm::scopeVisibilityToSection()→ section-level conditions).Backward compatibility
make()/schema()/makeForSection()new params are optional and default tonull.Tests
tests/Feature/ConsumerScopeHooksTest.php:VisibilityComponentlists all entity fields with no resolver (back-compat), constrains to the resolver subset when registered, and falls back to all when the resolver returnsnull.FieldForm::schema()builds unchanged with no resolver and accepts an optional section.Exercised end-to-end by the consuming application (a versioned Flex Fund Form builder): editing a field whose name exists in another form now saves, and the visibility dropdown lists only the current form's fields.