Problem/Motivation
SampleEntityGenerator::get() fills the sample entity with core's createWithSampleValues(), and a site cannot change those values.
A 255 character string field gets 26 to 254 characters, so a short text often wraps to two lines, and a long text field gets plain paragraphs with no markup.
Display Builder renders its entity view and preset previews from this entity, so the random values are what site builders design against.
Steps to reproduce
- Add a plain text field to the article content type, and use it with the body field in an article display or preset of Display Builder.
- The Canvas shows that field as one or two random lines and the body as unformatted paragraphs.
Proposed resolution
When field_sample_value is installed, get() passes the new entity to its populateWithSampleValues() before storing it in the tempstore.
It only touches fields with a generator configured, so the other fields keep core values, and sites without the module see no change.
The service is optional, so UI Patterns gets no new dependency.
Layout Builder+ also integrates field_sample_value.
A field config update now clears the cached sample, as a delete already does, or a newly configured generator only shows once the tempstore entry expires.
Base fields such as the node title stay on core values: field_sample_value only configures field config entities.
Remaining tasks
- Review.
User interface changes
None in UI Patterns. Generators are set on the field edit form, by field_sample_value.
API changes
SampleEntityGenerator takes an optional third constructor argument, the field_sample_value generator service.
Data model changes
None.
Issue fork ui_patterns-3631122
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 #4
mogtofu33 commentedComment #5
mogtofu33 commentedComment #7
just_like_good_vibesI would rather suggest to move this subject to core's SampleEntityGenerator
Comment #8
just_like_good_vibesComment #9
mogtofu33 commentedAgreed core is the right long term home, but that path is much longer: the values come from
ContentEntityStorageBase::createWithSampleValues(), which calls each field type's staticgenerateSampleValue()with no hook or event after it, so core needs a new API first.And core's generator,
LayoutBuilderSampleEntityGenerator, lives inside Layout Builder, which is why UI Patterns ships its own copy, so a change there would not reach UI Patterns anyway.Meanwhile this MR costs nothing: the service is optional, there is no new dependency, and sites without field_sample_value see no change.
This matters for Display Builder, the core defaults make previews feel broken, so if it is postponed here I will carry it as a patch there.
Happy to open the core issue in parallel and switch to it once it lands.