Overview
Splitting from https://git.drupalcode.org/project/canvas/-/merge_requests/992/diffs#not...
Canvas-provided JSON Schema object refs (e.g. json-schema-definitions://canvas.module/image, json-schema-definitions://canvas.module/video) are repeated as raw string literals across PHP source, tests, and config schema. Today the same URI string is hand-typed in ~12 distinct ref values across 144 PHP occurrences, with no central definition. This makes typos undetectable until runtime, hides which call sites need to change when a ref is renamed, and obscures the set of "well-known" refs Canvas exposes.
Proposed resolution
Introduce Drupal\canvas\JsonSchemaInterpreter\JsonSchemaObjectRef, a string-backed PHP enum whose cases hold the canonical URI for each Canvas-provided object ref declared in schema.json. Refactor every PHP call site to reference an enum case instead of a string literal — both in production code (JsonSchemaType::computeStorablePropShape(), ImageAdapter, ImageAndStyleAdapter, ShapeMatchingHooks::mediaLibraryStorablePropShapeAlter(), …) and in tests.
The enum exposes a propShape() helper returning the full {type: object, $ref: <URI> array, so existing shape-identity comparisons via PropShape::normalizePropSchema() need only minimal call-site changes.
The scope is explicitly and only for those type: object: Image and Video.
YAML config schema (config/schema/canvas.json_schema.yml) cannot reference the PHP enum as of today, so a comment pointing at the enum is sufficient there. In the future we might want to use the constants in yaml files too: #2951046: Allow parsing and writing PHP class constants and enums in YAML files.
Remaining tasks
- Add the enum and the
propShape()helper. - Refactor every PHP call site (production + tests) to use enum cases.
- Add a @see comment in
config/schema/canvas.json_schema.yml. - Confirm no functional change via existing PHPUnit coverage.
User interface changes
None.
Issue fork canvas-3587673
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
Comment #2
penyaskitoComment #3
penyaskitoComment #5
penyaskitoComment #6
longwaveAdded some comments.
Comment #7
penyaskitoComment #8
penyaskitoComment #9
longwaveMade some minor suggestions and one naming/typing question.
Comment #10
longwaveLooks good now, no further comments.
Comment #12
penyaskitoThanks! See you in #3586613: Add content-entity-reference well-known prop shape for code components