I have a set of external HTML files which I import into Nodes.
Also, external files have links to images which I'd like to import as Drupal files and make corresponding nodes to reference those files via File field.
I declared PagesMigration and FilesMigration and made Files dependent from Pages.
In PagesMigration class I add mapping for files:
$this->addFieldMapping('field_migrate_site_page_files', 'files');
and in prepareRow() method I collect image links from html and want to create files. So I suspect it should look like:
$files = getImageLinksFromHtml();
$row->files = $this->handleSourceMigration('SiteFiles', $files);
but this doesn't work, really. Also I don't want FilesMigration to be avaiable as separate migration procedure, as it is dependent from Page
Any ideas?
Comments
Comment #1
OnkelTem commentedComment #2
OnkelTem commentedOk, I created Gist: https://gist.github.com/OnkelTem/3f63e3295252cc81382a
So I use SitePagesMigration and SiteFilesMigration classes.
Comments to the code:
1) Files creation is initiated by
SitePagesMigration::prepareRow(), where I call2) Then the corresponding
SiteFilesMigration::createStub()is called to create files in Drupal and thus this is the only method for creating files.Questions:
1) As I create files "by hand" in
SiteFilesMigration::createStub(), do I really needSiteFilesMigrationclass at all? I use it now just to setup source, not even destination, as it is not used.2) Do I really need
MigrateFileLinkclass, which is used whenSiteFilesMigrationmigration is run separately? I'm not gonna runSiteFilesMigrationseparately, as it has no source data. But while I'm not gonna run it to Import, I'd like to use it for rollbacks and it wokrs just fine for that.3) As you see, I hard-coded site URLs. How to make it configurable?
Please, any ideas?
Comment #3
pifagor