You are here

public function Migration::addFieldMapping in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 includes/migration.inc \Migration::addFieldMapping()

Add a mapping for a destination field, specifying a source field and/or a default value.

Parameters

string $destinationField: Name of the destination field.

string $sourceField: Name of the source field (optional).

boolean $warn_on_override: Set to FALSE to prevent warnings when there's an existing mapping for this destination field.

17 calls to Migration::addFieldMapping()
BeerCommentMigration::__construct in migrate_example/beer.inc
General initialization of a Migration object.
BeerNodeMigration::__construct in migrate_example/beer.inc
General initialization of a Migration object.
BeerTermMigration::__construct in migrate_example/beer.inc
General initialization of a Migration object.
BeerUserMigration::__construct in migrate_example/beer.inc
General initialization of a Migration object.
GameBaseball::__construct in migrate_example_baseball/migrate_example_baseball.migrate.inc
General initialization of a Migration object.

... See full list

1 method overrides Migration::addFieldMapping()
XMLMigration::addFieldMapping in plugins/sources/xml.inc
So we can create our special field mapping class.

File

includes/migration.inc, line 368
Defines the base class for import/rollback processes.

Class

Migration
The base class for all import objects. This is where most of the smarts of the migrate module resides. Migrations are created by deriving from this class, and in the constructor (after calling parent::__construct()) initializing at a minimum the name,…

Code

public function addFieldMapping($destination_field, $source_field = NULL, $warn_on_override = TRUE) {

  // Warn of duplicate mappings
  if ($warn_on_override && !is_null($destination_field) && isset($this->codedFieldMappings[$destination_field])) {
    self::displayMessage(t('!name addFieldMapping: !dest was previously mapped from !source, overridden', array(
      '!name' => $this->machineName,
      '!dest' => $destination_field,
      '!source' => $this->codedFieldMappings[$destination_field]
        ->getSourceField(),
    )), 'warning');
  }
  $mapping = new MigrateFieldMapping($destination_field, $source_field);
  if (is_null($destination_field)) {
    $this->codedFieldMappings[] = $mapping;
  }
  else {
    $this->codedFieldMappings[$destination_field] = $mapping;
  }
  return $mapping;
}