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

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

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

michaellander created an issue. See original summary.

michaellander’s picture

michaellander’s picture

Assigned: Unassigned » michaellander

michaellander’s picture

Issue summary: View changes

This 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.

michaellander’s picture

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

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Needs work

Summaries 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.

michaellander’s picture

Issue summary: View changes
michaellander’s picture

Tbh, 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.

mglaman’s picture

Issue tags: +rosetta