Improve ::generateSampleValue() for common field types

Created on 13 April 2018, over 6 years ago
Updated 2 June 2024, 7 months ago

Problem/Motivation

All field types are capable of providing sample values via \Drupal\Core\Field\FieldItemInterface::generateSampleValue()

Layout Builder is one example of a UI that uses these sample values.

However, many of the samples are insufficient for actual display.
For example, a string field may generate a single string that is 255 characters long
See #2940212: [meta] Miscellaneous UI issues for the Layout Builder module β†’ for some screenshots where this is not desirable.

Proposed resolution

Improve each field type's ::generateSampleValue() implementation to provide a more usable value.

Remaining tasks

Identify which field types we need to improve
Open issues for each

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
FieldΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom catch

    At the moment this is tackling things in one patch rather than sub-issues, so moving to a task. If we want to split out we can do that later.

  • Status changed to Needs work almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    New functions will have to be typehinted
    Schema additions will need a post_update hook (with test case)

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    I'm looking into customizing generated dummy content using devel_generate. That uses the fields generateSampleValue() function.

    The two places I'm aware of this function being used are for in the Layout Builder UI and Devel Generate.

    In LB, I want to see dummy values that resemble my content.

    In Devel Generate, I want dummy values in line with the data I'm using.

    To override this function on a field... I have to create my own class and override the field?

    What I'm looking for is an easier way to override generateSampleValue().

  • Status changed to Needs review 7 months ago
  • πŸ‡­πŸ‡ΊHungary Sweetchuck Budapest

    @catch and @smustgrave Issue category changed from Plan to Task, and the issue status is "Needs work", but what exactly the proposed solution?

    If somebody wants to work on this, then where to start and a β€žhow to implement” guide would be useful.
    For me the hints from comment #29 is not enough.

    New functions will have to be typehinted
    Schema additions will need a post_update hook (with test case)

  • Status changed to Needs work 7 months ago
  • The Needs Review Queue Bot β†’ tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request β†’ . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

Production build 0.71.5 2024