You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[6.x] Add a read-only mode to the element selector index - #20516
Plugins can't embed an element index for elements that aren't nested elements. The embedded index is tied to an owner, field and attribute, so something like a customer's orders has nowhere to go, and the selector modal always selects and never links.
element-selector-modals/body now accepts readOnly. In that mode titles and thumbnails link to each element's edit page, rows can't be selected, and the source sidebar is hidden. The request's criteria already applied in the modal context, so a plugin narrows the list with those.
ReadOnlyElementIndex is exported from @craftcms/cp and wraps this: it takes an elementType, criteria and an optional storageKey (so several indexes of one element type keep separate view settings), fetches its own first payload, and renders ElementPicker in read-only mode. ElementIndex gets a selectable prop to hide the checkboxes, and ContentIndexViewModel gets a linksToElements() hook in place of the hard-coded modal check.
Criteria come from the client, as they already do for the modal. They only narrow what the user can already see, so nothing is signed.
Adds a reusable read-only element index so plugins can embed criteria-filtered lists outside nested-element fields, using the existing selector infrastructure.
Changes:
Exports ReadOnlyElementIndex with criteria and optional storage keys for independent view settings.
Adds read-only server rendering and disables selection and the source sidebar in embedded indexes.
Adds coverage for links, criteria filtering, selection suppression, and storage keys.
The first request omits viewMode, so its successful response contains no rows; mounting ElementPicker starts a second request through index.restore(). If that row request fails, it bypasses this wrapper's error handler and leaves the index pending with disabled controls and placeholders indefinitely. Forward the detached index's onError callback through useModalElementIndex and ElementPicker to this wrapper's error/retry state.
With readOnly: true and showFolders: true, this early return also delegates asset folders to the parent, which renders plain chips because folders have no edit URL. This removes the table's folder links, so a normal click no longer opens folders and keyboard users lose the focusable link. Delegate only non-folder elements to the parent so the existing data-folder-link branch remains available.
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
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
Plugins can't embed an element index for elements that aren't nested elements. The embedded index is tied to an owner, field and attribute, so something like a customer's orders has nowhere to go, and the selector modal always selects and never links.
element-selector-modals/bodynow acceptsreadOnly. In that mode titles and thumbnails link to each element's edit page, rows can't be selected, and the source sidebar is hidden. The request'scriteriaalready applied in the modal context, so a plugin narrows the list with those.ReadOnlyElementIndexis exported from@craftcms/cpand wraps this: it takes anelementType,criteriaand an optionalstorageKey(so several indexes of one element type keep separate view settings), fetches its own first payload, and rendersElementPickerin read-only mode.ElementIndexgets aselectableprop to hide the checkboxes, andContentIndexViewModelgets alinksToElements()hook in place of the hard-coded modal check.Criteria come from the client, as they already do for the modal. They only narrow what the user can already see, so nothing is signed.