Fix perform readonly transformation for lazyloaded searchabledropdown #11297
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.
Description
performReadonlyTransformation() on a SearchableDropdownField or SearchableMultiDropdownField, will convert the source DataList into an array, which requires pulling data for all records in the list from the database.
This is caused by the performReadonlyTransformation of the underlying SingleSelectField and MultiSelectField calling getSource. To circumvent this a new LazyLoadedLookupField is used. It has the same logic as SearchableDropdownTrait to use a Datalist internally for the Source.
This also contains the fix for #11294, since the wrong initial value of "Title" was messing up the control.
Please note: This solution feels like quite a hack. I really don't like the fact, that getSource is not really returning the source. But I figured as long as SearchableDropdownTrait works this way the performReadonlyTransformation should be similar to it.
Manual testing steps
Given ModelA has_one ModelB and ModelB has_many ModelA:
Issues
performReadonlyTransformation()
forSearchableDropdownField
andSearchableMultiDropdownField
doesn't respect lazy loading #11293Pull request checklist