fix(forms): resolve dependent fields via CoreVisibilityLogicService (fixes #149 strict-mode crash)#167
Open
crossi-dev wants to merge 1 commit into
Open
Conversation
…isibilityLogicService FormBuilder::getDependentFieldCodes() accessed $field->visibility_conditions, an attribute that does not exist on CustomField. Visibility data lives in settings->visibility and is already exposed through CoreVisibilityLogicService. Under Model::preventAccessingMissingAttributes() (Laravel strict mode) this threw MissingAttributeException and crashed every Filament form using custom fields. Replace the direct attribute access with app(CoreVisibilityLogicService::class) ->getDependentFields($field), which reads from the canonical settings path and returns the correct field_code strings (fixing the shape mismatch too: the old code expected ['field' => string] but VisibilityConditionData uses field_code). Closes relaticle#149
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.
Fixes #149
What's happening
With Laravel strict mode on (
Model::preventAccessingMissingAttributes()), rendering a form throwsMissingAttributeException: visibility_conditions.FormBuilder::getDependentFieldCodes()reads$field->visibility_conditions, but that attribute no longer exists onCustomField— visibility moved intosettings->visibilityand is read throughCoreVisibilityLogicService. Without strict mode it fails quietly (the access returnsnull), and the loop also still expects the old['field' => ...]shape rather than the currentfield_code, so dependent-field resolution was silently broken either way.The change
Route through the service the rest of the codebase already uses:
getDependentFields()returns the correctarray<string>of field codes, so both the strict-mode crash and the shape mismatch disappear in one move.Verified
(The 3 pre-existing
Dom\HTMLDocument not foundfailures are a PHP 8.4 DOM-extension thing, unrelated to this change.)Strict mode is getting recommended as a Laravel default now, so this one will bite more people over time — figured it was worth fixing properly rather than just guarding the access. I went with
app(CoreVisibilityLogicService::class)to match the call sites right next to it, but a couple of your builders take their collaborators via the constructor — want me to inject it that way instead for consistency? Happy either way.(I'm with Choreless — we fix and ship code for small teams — but no strings here, I just use Filament a lot.) — Charles