Problem/Motivation
Data definitions describe valid values, but can’t include examples. That leaves API docs without a concrete value to show and forms without useful placeholder text. generateSampleValue() creates random test data, so it doesn’t fill this need.
Steps to reproduce
Not applicable (feature request).
Proposed resolution
Add optional examples metadata to DataDefinition, with setExamples() and getExamples(). Docs and forms can use these examples. They’re descriptive only: they won’t be validated or affect runtime behavior.
Remaining tasks
- Follow-up: emit
examplesfrom the JSON Schema normalizers. (See #3623432: Emit data definition example values as the JSON Schema "examples" keyword)
User interface changes
None.
Introduced terminology
None.
API changes
Two new methods on DataDefinition (and potentially DataDefinitionInterface, subject to the same base-class-first BC approach as other metadata additions). Purely additive.
Data model changes
None. The definition array gains an optional key.
Release notes snippet
Data definitions can now declare example values via DataDefinition::setExamples(). Examples are descriptive metadata for consumers such as JSON Schema emitters, generated API documentation, and form placeholders; they are not validated and do not affect runtime behavior.
AI usage (if applicable)
- [x] AI Assisted Issue: This issue was generated with AI assistance, but was reviewed and refined by the creator.
- [x] AI Assisted Code: This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision.
Issue fork drupal-3620922
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
michaellander commentedComment #3
michaellander commentedComment #5
michaellander commentedThis branch and the default-value branch #3620920: Allow data definitions to declare a default value touch the same spots in the same four source files and both create the same new unit test file. Whichever lands second will need a rebase that merges the two DataDefinitionTest classes into one. That is mechanical, but worth noting in the issues so the committer isn't surprised.
Comment #6
michaellander commentedComment #7
michaellander commentedComment #8
smustgrave commentedSummaries need to be written in your own words vs AI please.
https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquett... this is posted here.
Comment #9
michaellander commentedComment #10
michaellander commentedTbh, I'm not really sure what to make of that feedback. Everything was reviewed, most was refined as necessary, and I attempted to balance enough information to make a case for the feature, while being concise enough to not waste anyones time. In this particular case, my module (Tool API) would benefit greatly from this, as it does automatic form generation from data definitions, it normalizes data definitions to JSON Schema and it's beneficial information for UI and AI use cases alike.
Comment #11
mglaman