Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Content fixtures

Security covered Under active development 107 sites

This module provides an API to programmatically generate and load content into your Drupal site, useful for development or presentation. It allows you to define custom content generators and run them with a single command, including options to purge existing content before loading new fixtures.

Introduction

Do you want to build a running website straight from your repository, but you realized that you have to get some dummy content from somewhere? Search no more. This module will give you an API to program your own content generators, that you will be able to run with one command, and fill your website with content required either for development or presentation.

This module is different from data_fixtures in that it aims to mimic as much as it's reasonably possible DoctrineFixturesBundle.

It was made with a workflow of programmatically building your website from scratch in mind, and tries to avoid any ambiguous states, that's why it deletes all content before loading any fixtures (don't worry, it will warn you :) ).

Great match with Docker, if you are looking for ultimate automation.

How to

This module has API very similar to DoctrineFixturesBundle, with some Drupal-specific differences/simplifications.

Basics

Minimally, your fixture class has to implement FixtureInterface, and be registered as a service tagged with a content_fixture tag.

Sharing objects between fixtures.

The easiest way of achieving this is to extend AbstractFixture class, that will provide you with some additional sugar - this abstract class implements SharedFixtureInterface that will give you a way of sharing created objects between fixtures.

Order of execution of fixtures

For this to work, you have to be able to decide on the order of execution of fixtures, and you can do this in two ways:

1. By implementing OrderedFixtureInterface - this will allow you to assign a value to each fixture, that will be used for ordering.
2. By implementing DependentFixtureInterface, that will allow you to declare dependencies between fixtures, and order of execution will be calculated by using this information.

Groups

You can also implement FixtureGroupInterface in your fixture, to assign it to some custom groups. It will allow you to run fixtures by groups they belong to. This way you can have different set of fixtures for presentation, different for development etc.

Execution

You need drush to run your fixtures. Module provides you with three commands:

  • content-fixtures:list
  • content-fixtures:load
  • content-fixtures:purge

See: drush help content-fixtures:list, drush help content-fixtures:load, and drush help content-fixtures:purge.

Other

If you like code quality of this module but you would rather like to have exportable hand-made content, then you may consider content_snapshot module.

Happy coding!

Drupal 8–11

Ask your assistant about Content fixtures

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
3
Tracked since
Mar 2023
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
3.2.0 Stable 8–11 Jan 17, 2025
3.1.4 Stable 8–10 PHP >=7.1.0 Jul 19, 2023
3.1.3 Stable 8–10 PHP >=7.1.0 Mar 11, 2023