#3591885: Add `document` object $ref for linking locally hosted documents
Adds the document object $ref agreed in #3524130, note 1678367, mirroring the shipped video shape point for point.
What this branch does
schema.json: adds thedocumentdefinition withsrc(required),title,description,filename,filesize, andmimetype.srccarriescontentMediaType: application/*— every agreed extension (pdf doc docx xls xlsx ppt pptm pptx key ai indd) resolves to theapplicationMIME media type, and the wildcard is what makes field matching precise (see below).JsonSchemaObjectRef: adds theDocumentcase;canvas.json_schema.ymlallows the new URI in theChoiceconstraint.JsonSchemaType::computeStorablePropShape():Documentarm using thefile_genericwidget.srcresolves the referenced File entityurito an absolute URL;filename,filesize, andmimetyperesolve from the File entityfilename,filesize, andfilemimeproperties.ShapeMatchingHooks: mapsDocumentto theFilemedia source so sites with Media Library get the media picker, includingfilename/filesize/mimetypein each bundle branch.VideoFileextendsFile, sogetMediaTypesForSource()now skips media types whose source has a more specificSCHEMA_TO_MEDIA_SOURCEentry — video media types stay out of document props.- First commit fixes a latent matcher bug this shape exposed: the
UriTargetMediaTyperequirement was only applied forcontentMediaType: image/*andvideo/*. Withapplication/*falling through to the loose branch, the matcher accepted URI properties targeting any media type and assembled nonsense object matches (e.g.titlefrom a file fielddescription). The requirement now applies to every valid wildcard. - Docs:
component-metadata.mdxgains a Document section.
Deviations from note 1678367
titleanddescriptionare not resolved by the storable prop shape or the media mapping:FieldObjectPropsExpressionrequires every sub-expression to target the same field item, so the Media entity label is not reachable from the source field. Both stay populatable via static prop sources.- The code editor "Document" prop type is not included — video shipped its editor UI separately in #3534601, and this follows the same split. Follow-up issue to come.
AI-Generated: Yes (Used Claude Code to implement the agreed proposal, diagnose the wildcard contentMediaType matcher gap, and update tests and docs; reviewed by @mglaman).
Testing instructions
- Enable
sdc_test_all_propsand confirm theall-propscomponent exposestest_object_drupal_documentwith a file upload limited to the agreed document extensions. - Create a
filesource media type, re-open the component: the prop now offers the media library picker, and video media types are not selectable. - Place the component, select a PDF, confirm the rendered output shows the absolute file URL, filename, file size, and MIME type.
-
composer run phpunit -- tests/src/Kernel/PropShapeRepositoryTest.php tests/src/Kernel/MediaLibraryHookStoragePropAlterTest.php tests/src/Kernel/ShapeMatcher/