You are here

public function MigrateDestinationEntity::prepare in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 plugins/destinations/entity.inc \MigrateDestinationEntity::prepare()

Give handlers a shot at modifying the object before saving it.

Parameters

$entity: Entity object to build. Prefilled with any fields mapped in the Migration.

$source_row: Raw source data object - passed through to prepare handlers.

5 calls to MigrateDestinationEntity::prepare()
MigrateDestinationComment::import in plugins/destinations/comment.inc
Import a single comment.
MigrateDestinationFile::import in plugins/destinations/file.inc
Import a single file record.
MigrateDestinationNode::import in plugins/destinations/node.inc
Import a single node.
MigrateDestinationTerm::import in plugins/destinations/term.inc
Import a single term.
MigrateDestinationUser::import in plugins/destinations/user.inc
Import a single user.

File

plugins/destinations/entity.inc, line 129
Defines base for migration destinations implemented as Drupal entities.

Class

MigrateDestinationEntity
Abstract base class for entity-based destination handling. Holds common Field API-related functions.

Code

public function prepare($entity, stdClass $source_row) {

  // Add source keys for debugging and identification of migrated data by hooks.

  /* TODO: Restore
     foreach ($migration->sourceKeyMap() as $field_name => $key_name) {
       $keys[$key_name] = $source_row->{$field_name};
     }
     */
  $migration = Migration::currentMigration();
  $entity->migrate = array(
    //      'source_keys' => $keys,
    'machineName' => $migration
      ->getMachineName(),
  );

  // Call any general entity handlers (in particular, the builtin field handler)
  migrate_handler_invoke_all('Entity', 'prepare', $entity, $source_row);

  // Then call any entity-specific handlers
  migrate_handler_invoke_all($this->entityType, 'prepare', $entity, $source_row);

  // Apply defaults, removing empty fields from the entity object.
  $form = $form_state = array();
  _field_invoke_default('submit', $this->entityType, $entity, $form, $form_state);

  // Then call any prepare handler for this specific Migration.
  if (method_exists($migration, 'prepare')) {
    $migration
      ->prepare($entity, $source_row);
  }
}