New in Drupal 11: Export Content to YAML with the content:export Command
With the release of Drupal 11.3.0, a powerful new tool has landed in core: the content:export Drush command. This feature simplifies how developers generate YAML-formatted content for installation recipes, testing, and automation pipelines.
Why You Should Care
Until now, creating YAML-based content recipes required third-party modules like Default Content, or time-consuming manual work. With content:export, this process is streamlined and integrated into Drupal core — no extra modules needed.
How to Use content:export
From your Drupal root directory, run:
php core/scripts/drupal content:export <ENTITY_TYPE_ID> <ENTITY_ID>
Example:
php core/scripts/drupal content:export node 123 > recipes/my_article.yml
This command exports the entity (in this case, a node) into a YAML file that’s immediately ready for use in recipes, automated tests, or migration setups.
What You Need to Know
- Exports one entity at a time
- Related dependencies (like attached images or taxonomy terms) are detected but not exported automatically
- Core field types are supported. Custom field types may require integration code.
- Entities can also be exported programmatically via the
default_content.exporterservice.
Extending Export Behavior
Need more control? You can hook into the PreExportEvent event to:
- Skip specific fields from being exported
- Provide custom export logic for custom field types
- Include computed fields in the export
Example Use Cases
Exporting a taxonomy term:
php core/scripts/drupal content:export taxonomy_term 40 > taxonomy.yml
Programmatic export:
use Drupal\node\Entity\Node;
use Drupal\Core\DefaultContent\Exporter;
$node = Node::load(32);
$export = \Drupal::service(Exporter::class)->export($node);
Who Will Benefit?
- Drupal developers building test fixtures or installation profiles
- DevOps engineers automating content deployment
- Distribution maintainers and module authors
- QA teams writing reliable test suites
Final Thoughts
The content:export command is a welcome addition to the Drupal developer’s toolbox. It reduces manual work, improves testability, and brings content recipes closer to core best practices.
If you’re using Drupal 11.3.0 or later, give it a try and accelerate your content-driven development process.
🔗 Source: Drupal.org Change Record
🚀 Need help integrating content automation into your Drupal workflow? Contact our team of experts.
Comments