Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: MCP Sentinel 2.29.0 — Minor update available for module mcp_sentinel (2.29.0). Release: Audit Chain 1.10.9 — Minor update available for module audit_chain (1.10.9). Release: Menu Autopilot 1.4.7 — Minor update available for module menu_autopilot (1.4.7). Release: FileGate 1.11.3 — Minor update available for module file_gate (1.11.3). Release: Download Tracker 1.0.7 — Minor update available for module download_tracker (1.0.7). Release: Directory2Block Slideshow 1.0.8 — Minor update available for module directory2block_slideshow (1.0.8). Release: Mautic Audiences 1.1.5 — Minor update available for module mautic_audiences (1.1.5). Release: Rightup theme 1.0.3 — Minor update available for theme vartheme_bs5_rightup (1.0.3). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

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;
  }

}

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
1
Tracked since
Feb 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core Release date
1.0.0 Stable Feb 24, 2023