Problem/Motivation
When working with AI tools to generate or review content, the AI needs to understand the field constraints of each entity type: what fields exist, their types, cardinality, allowed values, required status, and so on. Currently there is no way to export this structural information in a machine-readable format without manually inspecting the Drupal UI or reading raw config YAML.
The existing content-first:export command exports rendered content. There is no equivalent for exporting the architecture — the field schema — of entity types.
Proposed resolution
Add a new drush command content-first:export-architecture (alias cf:architecture) that introspects field definitions using EntityFieldManagerInterface and writes one YAML file per entity type, with all bundles nested inside.
Example output for architecture-entity-node.yml:
_defaults: langcode: type: string label: Language mandatory: false translatable: true limit: no cardinality: 1 status: type: boolean label: Published mandatory: false translatable: false limit: no cardinality: 1 article: _description: "Use articles for time-sensitive content." field_image: type: image label: Image mandatory: false translatable: true limit: no cardinality: 1 allowed_extensions: [jpg, jpeg, png, webp] alt_required: true field_tags: type: taxonomy label: Tags mandatory: false translatable: false limit: no cardinality: unlimited target_type: taxonomy_term target_bundles: [tags] The command supports:
--entity-types— comma-separated entity type IDs to export (default:node)--bundles— optional bundle filter--folder— output directory (default:private://content_first/)--follow-references— auto-discovers and exports referenced entity types (paragraphs, taxonomy terms, etc.)
A new service EntityArchitectureExporter handles all field inspection logic. It exports the following per field:
- Human-readable
type(e.g.textarea,taxonomy,paragraphs,select) label,description(when set),mandatory,translatablelimit(max_length for string fields,nootherwise),cardinalitydefaultvalue when configured- For
selectfields:optionskey-value map - For
text/textareafields:allowed_formats - For
file/imagefields:allowed_extensions,max_filesize,alt_required,min_resolution/max_resolution - For numeric fields:
min,max,prefix,suffix - For
linkfields:link_type(internal/external/any),link_title - For entity reference fields:
target_typeandtarget_bundles
Fields that are identical across all bundles are hoisted into a _defaults section to reduce repetition. Bundle descriptions (from getDescription() on the bundle entity) appear as _description.
Internal and system fields are excluded: nid, tid, vid, uuid, all revision_ fields, created, changed, default_langcode, content_translation_, moderation_state, promote, sticky, layout_builder__layout.
Remaining tasks
- Review and test against sites using paragraphs, media, and taxonomy references
- Add unit tests for
EntityArchitectureExporter - Consider whether
_defaultsextraction should be opt-out via a flag
API changes
New service content_first.entity_architecture_exporter — class Drupal\content_first\Architecture\EntityArchitectureExporter.
New drush command content-first:export-architecture / cf:architecture added to ContentFirstCommands. The constructor gains three new arguments: EntityFieldManagerInterface, EntityTypeBundleInfoInterface, and EntityArchitectureExporter.
Issue fork content_first-3593733
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 #3
gedur commented