Repository navigation
[6.x] Allow addons to reuse relationship components - #15839
Open
duncanmcclean wants to merge 1 commit into
Open
duncanmcclean wants to merge 1 commit into
duncanmcclean wants to merge 1 commit into
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-2c2291ae-edc1-4e69-8693-c58a8e0a7963 Co-authored-by: Duncan McClean <duncan@duncanmcclean.com>
This branch has not been deployed
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.
This pull request lets addons reuse the CMS relationship components while providing their own selection and creation UI.
Use case
The use case is Runway's new Eloquent Relationship fieldtype. For morph relationships, related records can belong to different resources—for example, a comment might belong to either a post or a video. The selector needs a resource switcher alongside search, and creation targets that aren’t necessarily blueprints.
This PR provides the generic UI hooks needed to implement that on the Runway side, without needing to copy components from
cms.Usage
The following components are now exported from
@statamic/cms:RelationshipInput,RelationshipSelector,RelationshipSelectField,RelationshipCreateButtonandInlineCreateForm.RelationshipInputhas aselectorslot inside its existing selector stack. The slot receivesselect(ids)andclose()callbacks. Call both to apply a selection and dismiss the stack, or onlyclose()to cancel. Without the slot, the ordinary selector is used.RelationshipSelectorhas atoolbarslot alongside its existing search and filter controls:The toolbar uses 20% of the available width on wide selectors and 40% on narrow selectors, with search filling the remainder. Selectors without custom toolbar controls keep their existing search sizing.
RelationshipCreateButtonaccepts a translatedmenuLabel, and each creation target can provide translatedlabelandhintvalues alongside itsurl. These fall back to the existing “Choose Blueprint”,blueprintandparent_titlevalues. Zero targets show no create control, one opens creation directly, and multiple show the menu.RelationshipInputforwardscreateMenuLabelto the button; relationship fieldtypes can supply it throughmeta.createMenuLabel.Screenshots
Amp thread: https://ampcode.com/threads/T-2c2291ae-edc1-4e69-8693-c58a8e0a7963