Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
myselfhimself CreditAttribution: myselfhimself commented