You are here

public function CckMigration::buildMigrations in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/migrate_drupal/src/Plugin/migrate/builder/d6/CckMigration.php \Drupal\migrate_drupal\Plugin\migrate\builder\d6\CckMigration::buildMigrations()

Builds migration entities based on a template.

Parameters

array $template: The parsed template.

Return value

\Drupal\migrate\Entity\MigrationInterface[] The unsaved migrations generated from the template.

Overrides MigrateBuilderInterface::buildMigrations

File

core/modules/migrate_drupal/src/Plugin/migrate/builder/d6/CckMigration.php, line 30
Contains \Drupal\migrate_drupal\Plugin\migrate\builder\d6\CckMigration.

Class

CckMigration
Plugin annotation @PluginID("d6_cck_migration");

Namespace

Drupal\migrate_drupal\Plugin\migrate\builder\d6

Code

public function buildMigrations(array $template) {
  $migration = Migration::create($template);
  $source_plugin = $migration
    ->getSourcePlugin();

  // The source plugin will throw RequirementsException if CCK is not enabled,
  // in which case there is nothing else for us to do.
  if ($source_plugin instanceof RequirementsInterface) {
    try {
      $source_plugin
        ->checkRequirements();
    } catch (RequirementsException $e) {
      return [
        $migration,
      ];
    }
  }

  // Loop through every field that will be migrated.
  foreach ($source_plugin as $field) {
    $field_type = $field
      ->getSourceProperty('type');

    // Each field type should only be processed once.
    if (in_array($field_type, $this->processedFieldTypes)) {
      continue;
    }
    elseif ($this->cckPluginManager
      ->hasDefinition($field_type)) {
      $this->processedFieldTypes[] = $field_type;

      // Allow the cckfield plugin to alter the migration as necessary so that
      // it knows how to handle fields of this type.
      $this->cckPluginManager
        ->createInstance($field_type, [], $migration)
        ->{$this->configuration['cck_plugin_method']}($migration);
    }
  }
  return [
    $migration,
  ];
}