You are here

public function Migration::getFieldMappings in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 includes/migration.inc \Migration::getFieldMappings()
2 calls to Migration::getFieldMappings()
Migration::applyMappings in includes/migration.inc
Apply field mappings to a data row received from the source, returning a populated destination object.
XMLMigration::applyMappings in plugins/sources/xml.inc
A normal $data_row has all the input data as top-level fields - in this case, however, the data is embedded within a SimpleXMLElement object in $data_row->xml. Explode that out to the normal form, and pass on to the normal implementation.

File

includes/migration.inc, line 154
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 getFieldMappings() {
  if (empty($allFieldMappings)) {
    $this->allFieldMappings = array_merge($this
      ->getCodedFieldMappings(), $this
      ->getStoredFieldMappings());

    // If there are multiple mappings of a given source field to no
    // destination field, keep only the last (so the UI can override a source
    // field DNM that was defined in code).
    $no_destination = array();

    // But also remove a mapping of a source field to nothing, if there is
    // a mapping to something.
    $mapped_source_fields = array();

    /** @var MigrateFieldMapping $mapping */
    foreach ($this->allFieldMappings as $destination_field => $mapping) {
      $source_field = $mapping
        ->getSourceField();

      // If the source field is not mapped to a destination field, the
      // array index is integer.
      if (is_int($destination_field)) {
        if (isset($no_destination[$source_field])) {
          unset($this->allFieldMappings[$no_destination[$source_field]]);
          unset($no_destination[$source_field]);
        }
        $no_destination[$source_field] = $destination_field;
        if (isset($mapped_source_fields[$source_field])) {
          unset($this->allFieldMappings[$destination_field]);
        }
      }
      else {
        $mapped_source_fields[$source_field] = $source_field;
      }
    }

    // Make sure primary fields come before their subfields
    ksort($this->allFieldMappings);
  }
  return $this->allFieldMappings;
}