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

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 tags: -AI-accelerated +AI-accelerated. blocker
penyaskito’s picture

Issue tags: -AI-accelerated. blocker +AI-accelerated, +blocker

penyaskito’s picture

Assigned: Unassigned » longwave
Status: Active » Needs review
longwave’s picture

Assigned: longwave » penyaskito
Status: Needs review » Needs work

Added some comments.

penyaskito’s picture

Status: Needs work » Needs review
penyaskito’s picture

Assigned: penyaskito » longwave
longwave’s picture

Assigned: longwave » penyaskito
Status: Needs review » Needs work

Made some minor suggestions and one naming/typing question.

longwave’s picture

Status: Needs work » Reviewed & tested by the community

Looks good now, no further comments.

  • penyaskito committed 558f4da2 on 1.x
    chore(Shape matching): #3587673 Introduce `JsonSchemaObjectRef` enum to...
penyaskito’s picture

Assigned: penyaskito » Unassigned
Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.