Overview

To configure a JS component's content-entity-reference dependencies, an editor needs to pick a target entity type and bundle and then choose which of its fields the component should bind to. Two pieces of information are missing from the Canvas HTTP API today:

  1. The fieldable content entity types and bundles available on the site, filtered to those the current user can view.
  2. The fields on a given entity type and bundle that can drive a JS component prop, with pre-built expression strings — including navigation through reference fields.

Existing endpoints under /canvas/api/v0/ui/content_template/suggestions/* are coupled to a specific Component config entity and cannot serve a generic editor configuring content-entity-reference dependencies.

This issue unblocks the UI work tracked in #3585355: [PP-1] Entity Reference Selection UI.

Proposed resolution

Add two read-only endpoints under /canvas/api/v0/ui/entity-reference/*:

  • GET …/content-entity-types — fieldable content entity types and their bundles, filtered by per-bundle view access. Bundle-less entity types are surfaced with a single self-named bundle.
  • GET …/fields/{entity_type}/{bundle} — field descriptors with pre-built expression strings. An optional ?parent=[expression] chains the response to a reference path so the UI can lazily expand reference fields without constructing expressions itself.

Per-bundle and per-field view access checks run against an unsaved stub entity so internal fields (e.g. the user pass hash) are not surfaced to editors who can't read them. Every hop in a ?parent= reference chain is also access-checked.

Image, file, link, and entity references whose target is a Media bundle with a known source plugin (Image, VideoFile) surface a single object expression — {src, alt, width, height} for image-shaped data, {src} for file/video, {uri, title} for links — instead of an expandable reference. src chains through the referenced file's uri.url so the editor receives a URL, not a file entity. This mirrors the canonical shapes in ShapeMatchingHooks::getObjectProps(). All other entity references stay expandable through ?parent=.

Both endpoints are documented in openapi.yml and validated at runtime by ApiResponseValidator.

Remaining tasks

  • Follow-up: collapse the per-field-type object mappings into a typed-data-driven helper shared with EntityFieldPropSourceMatcher. Marked with a @todo in the controller; out of scope for this issue.

User interface changes

None in this issue. The editor UI consuming these endpoints is tracked in #3585355: [PP-1] Entity Reference Selection UI.

API changes

  • Added: GET /canvas/api/v0/ui/entity-reference/content-entity-types
  • Added: GET /canvas/api/v0/ui/entity-reference/fields/{entity_type}/{bundle}

Data model changes

None.

Issue fork canvas-3585354

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

penyaskito created an issue. See original summary.

penyaskito’s picture

Issue summary: View changes
Issue tags: +Needs security review

Updated issue summary with access checks + more details

penyaskito’s picture

Issue summary: View changes

Just formatting.

wim leers’s picture

Priority: Normal » Major
Issue tags: +blocker
Related issues: +#3585355: [PP-1] Entity Reference Selection UI

penyaskito’s picture

Issue summary: View changes