Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Migrate Faker

Security covered Under active development

This module uses the Faker library to generate fake data for Drupal migrations. It allows you to easily create placeholder content like text, numbers, or other data types directly within your migration process. You can use the default Faker setup or define your own custom service for more specialized data generation.

This modules allows to use the Faker package to create fake data when running migrations.

You can either use the default faker instance, or create a custom service to instantiate a custom faker instance.

Mode of use: Simple approach

In this example, the Faker::text will be called to generate a fake English based text.

process:
  field_text/value:
    - plugin: faker
      generator: text 
process:
  field_number:
    - plugin: faker
      generator: randomDigit 
process:
  field_number:
    - plugin: faker
      generator: numberBetween  # Use args to specify argument to the generator.
      args:
        - 20
        - 30

Some generators produce an array of values, you can join them using the contact plugin.

process:
  field_text/value:
    - plugin: faker
      generator: paragraphs
    - plugin: concat
      delimiter: "\n\n"

Mode of use: Custom service

process:
  field_text/value:
    - plugin: faker
      generator: text
      #This service will be in charge or creating the faker instance
      faker_factory_service: mymodule.faker_factory_service  
      # The locale to use when creating the faker instance
      faker_locale: _locale
<?php

namespace Drupal\mymodule;

use Drupal\migrate_faker\FakerFactoryServiceInterface;
use Faker\Factory;

/**
 * A Faker Factory service to create English or Arabic strings.
 */
class FakerFactoryService implements FakerFactoryServiceInterface {

  /**
   * {@inheritdoc}
   */
  public function create(string $locale) {
    $faker = Factory::create($locale);
    if ($locale === 'ar_SA') {
      // TextProviderEn is a custom class that extends use Faker\Provider\ar_SA\Text 
      // to define custom Arabic content;
      $faker->addProvider(new TextProviderAr($faker));
      return $faker;
    }

    // TextProviderEn is a custom class that extends use Faker\Provider\en_US\Text 
    // to define custom English content;
    $faker->addProvider(new TextProviderEn($faker));
    return $faker;
  }

}
Drupal 8–10 · not 11

Ask your assistant about Migrate Faker

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

  • migrate Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Feb 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core PHP Release date
1.0.0 Stable 8–10 Feb 24, 2023