You are here

class MigrationBuilder in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/MigrationBuilder.php \Drupal\migrate\MigrationBuilder

Builds migration entities from migration templates.

Hierarchy

Expanded class hierarchy of MigrationBuilder

1 string reference to 'MigrationBuilder'
migrate.services.yml in core/modules/migrate/migrate.services.yml
core/modules/migrate/migrate.services.yml
1 service uses MigrationBuilder
migrate.migration_builder in core/modules/migrate/migrate.services.yml
Drupal\migrate\MigrationBuilder

File

core/modules/migrate/src/MigrationBuilder.php, line 16
Contains \Drupal\migrate\MigrationBuilder.

Namespace

Drupal\migrate
View source
class MigrationBuilder {

  /**
   * The builder plugin manager.
   *
   * @var \Drupal\migrate\Plugin\MigratePluginManager
   */
  protected $builderManager;

  /**
   * Constructs a MigrationBuilder.
   *
   * @param \Drupal\migrate\Plugin\MigratePluginManager $builder_manager
   *   The builder plugin manager.
   */
  public function __construct(MigratePluginManager $builder_manager) {
    $this->builderManager = $builder_manager;
  }

  /**
   * Builds migration entities from templates.
   *
   * @param array $templates
   *   The parsed templates (each of which is an array parsed from YAML), keyed
   *   by ID.
   *
   * @return \Drupal\migrate\Entity\MigrationInterface[]
   *   The migration entities derived from the templates.
   */
  public function createMigrations(array $templates) {

    /** @var \Drupal\migrate\Entity\MigrationInterface[] $migrations */
    $migrations = [];
    foreach ($templates as $template_id => $template) {
      if (isset($template['builder'])) {
        $variants = $this->builderManager
          ->createInstance($template['builder']['plugin'], $template['builder'])
          ->buildMigrations($template);
      }
      else {
        $variants = array(
          Migration::create($template),
        );
      }

      /** @var \Drupal\migrate\Entity\MigrationInterface[] $variants */
      foreach ($variants as $variant) {
        $variant
          ->set('template', $template_id);
      }
      $migrations = array_merge($migrations, $variants);
    }
    return $migrations;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrationBuilder::$builderManager protected property The builder plugin manager.
MigrationBuilder::createMigrations public function Builds migration entities from templates.
MigrationBuilder::__construct public function Constructs a MigrationBuilder.