[6.x] Support reference updates for custom fieldtypes #13693
+260
−0
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.
Problem
Statamic's
DataReferenceUpdaterdelegates asset reference updates toAssetReferenceUpdater, which only supports Statamic's built-in fieldtypes. Custom fieldtypes referencing assets or containing nested fields (including nested Statamic Asset fields) don't receive reference updates when assets are renamed, moved, or deleted. This causes broken references.Because of this, I had to disable renaming and moving files entirely in all of my projects.
Solution
This PR introduces a new approach: fieldtypes handle their own reference updates via the
UpdatesReferencestrait. Since only the fieldtype knows its internal data structure, I think it's best positioned to locate and replace references.Custom fieldtypes containing asset/term fields or nested structures (flat or array based) can implement this trait to opt into reference updating.
Example
A fieldtype containing asset references
A fieldtype with nested fields
Status
This is still a work in progress. I'd appreciate early feedback on whether this approach makes sense before I complete the implementation.
Closes statamic/ideas#698