Hello,

Thanks for the awesome asset module!

There is already good Migrate module support for the Asset module thank you, with namely a MigrateDestinationAsset class !

Here's a piece of code that may help people having stub assets :

class MyAssetMigration extends Migration{
  function __construct(...) {
    ...
    $this->destination = new MigrateDestinationAsset(...);
    ...
  }

  /**
   * Stubs solution to chicken and eggs problem for field_voir_aussi entity
   * reference field.
   * @see https://drupal.org/node/1013506
   *
   * @param $migration
   * @param $source_id
   */
  protected function createStub(Migration $migration, array $source_id) {
    $title = t('Stub asset of type @type pour source id @id', array(
      '@type' => $this->destination->getBundle(),
      '@id'   => $source_id[0],
    ));

    $entity = entity_create('asset', array(
      'type' => $this->destination->getBundle(),
      'title' => $title,
      'uid' => MyMainMigration::getDefaultUid(),
      )
    );

    $entity->save();

    $ew = entity_metadata_wrapper('asset', $entity);
    // Example non-standard field filling
    $ew->field_asset_html->set('<p>Temporary html text for free html asset</p>');
    $ew->save();

    if (isset($entity->aid)) {
      return array($entity->aid);
    }
    else {
      return FALSE;
    }
  }

Comments

myselfhimself’s picture

Title: createStub method for Migrate_d2d module » Asset createStub example method for Migrate module
Issue summary: View changes
Issue tags: -migrate_d2d