You are here

public function FieldDiscovery::addBundleFieldProcesses in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/migrate_drupal/src/FieldDiscovery.php \Drupal\migrate_drupal\FieldDiscovery::addBundleFieldProcesses()

Adds the field processes for a bundle to a migration.

Parameters

\Drupal\migrate\Plugin\MigrationInterface $migration: The migration to add processes to.

string $entity_type_id: The legacy entity type to add processes for.

string $bundle: The legacy bundle (or content_type) to add processes for.

Throws

\InvalidArgumentException

Overrides FieldDiscoveryInterface::addBundleFieldProcesses

1 call to FieldDiscovery::addBundleFieldProcesses()
FieldDiscovery::addEntityFieldProcesses in core/modules/migrate_drupal/src/FieldDiscovery.php
Adds the field processes for an entity to a migration.

File

core/modules/migrate_drupal/src/FieldDiscovery.php, line 143

Class

FieldDiscovery
Provides field discovery for Drupal 6 & 7 migrations.

Namespace

Drupal\migrate_drupal

Code

public function addBundleFieldProcesses(MigrationInterface $migration, $entity_type_id, $bundle) {
  $core = $this
    ->getCoreVersion($migration);
  $fields = $this
    ->getAllFields($core);
  $plugin_definition = $migration
    ->getPluginDefinition();
  if (empty($fields[$entity_type_id][$bundle])) {
    return;
  }
  $bundle_fields = $fields[$entity_type_id][$bundle];
  foreach ($bundle_fields as $field_name => $field_info) {
    $plugin = $this
      ->getFieldPlugin($field_info['type'], $migration);
    if ($plugin) {
      $method = isset($plugin_definition['field_plugin_method']) ? $plugin_definition['field_plugin_method'] : 'defineValueProcessPipeline';

      // @todo Remove the following 3 lines of code prior to Drupal 9.0.0.
      // https://www.drupal.org/node/3032317
      if ($plugin instanceof MigrateCckFieldInterface) {
        $method = isset($plugin_definition['cck_plugin_method']) ? $plugin_definition['cck_plugin_method'] : 'processCckFieldValues';
      }
      call_user_func_array([
        $plugin,
        $method,
      ], [
        $migration,
        $field_name,
        $field_info,
      ]);
    }
    else {

      // Default to a get process plugin if this is a value migration.
      if ((empty($plugin_definition['field_plugin_method']) || $plugin_definition['field_plugin_method'] === 'defineValueProcessPipeline') && (empty($plugin_definition['cck_plugin_method']) || $plugin_definition['cck_plugin_method'] === 'processCckFieldValues')) {
        $migration
          ->setProcessOfProperty($field_name, $field_name);
      }
    }
  }
}