Problem/Motivation
When an SDC component is assigned to a File or Image field formatter within an entity view mode, Drupal generates a dummy sample file in the managed files system (file_managed table). While sample files generated for Image fields are marked as temporary, those generated for File fields are created as permanent files. Furthermore, whenever the same field is reused in another content type, an additional dummy file is automatically generated.
In addition, if the field is an Image field configured to only allow .svg extensions (for example, when using the svg_image module), generating dummy content causes a fatal error and breaks the site completely, as the default dummy file generation mechanism fails to handle SVG files properly.
Steps to reproduce
- Enable the ui_patterns_field_formatters module.
- Create a content type and add a File or Image field to it.
- Navigate to the entity's Manage Display view mode settings and set the field to render using any SDC component.
- Go to Admin > Content > Files (/admin/content/files) and observe that sample file entries have been created in the managed files directory.
- Create a second content type and reuse the existing File/Image field. Check the files list again to observe that additional sample files have been generated.
Proposed resolution
In ui_patterns_field_formatters/src/Plugin/Field/FieldFormatter/FormatterBase.php, the getComponentSourceContexts() method generates sample field content when no entity instance exists. Update this logic to prevent auto-generating dummy sample files in the managed files system during component context resolution.
Issue fork ui_patterns-3623890
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 #5
cbccharlie commentedComment #6
just_like_good_vibes