protected function MediaEntityGeneratorTaxonomyD7::initializeIterator in Migrate File Entities to Media Entities 8
Initializes the iterator with the source data.
Return value
\Iterator Returns an iteratable object of data for this source.
Overrides SqlBase::initializeIterator
File
- src/
Plugin/ migrate/ source/ MediaEntityGeneratorTaxonomyD7.php, line 136
Class
- MediaEntityGeneratorTaxonomyD7
- Returns bare-bones information about every available file entity.
Namespace
Drupal\migrate_file_to_media\Plugin\migrate\sourceCode
protected function initializeIterator() {
$query_files = $this
->select('file_managed', 'f')
->fields('f')
->condition('uri', 'temporary://%', 'NOT LIKE')
->orderBy('f.timestamp');
$all_files = $query_files
->execute()
->fetchAllAssoc('fid');
$files_found = [];
foreach ($this->sourceFields as $name => $source_field) {
$parent_iterator = parent::initializeIterator();
foreach ($parent_iterator as $entity) {
$id = $entity['tid'];
$field_value = $this
->getFieldValues($this->configuration['entity_type'], $name, $id);
foreach ($field_value as $reference) {
// Support remote file urls.
$file_url = $all_files[$reference['fid']]['uri'];
if (!empty($this->configuration['d7_file_url'])) {
$file_url = str_replace('public://', '', $file_url);
$file_path = rawurlencode($file_url);
$file_url = $this->configuration['d7_file_url'] . $file_path;
}
if (!empty($all_files[$reference['fid']]['uri'])) {
$files_found[] = [
'tid' => $entity['tid'],
'target_id' => $reference['fid'],
'alt' => isset($reference['alt']) ? $reference['alt'] : NULL,
'title' => isset($reference['title']) ? $reference['title'] : NULL,
'display' => isset($reference['display']) ? $reference['display'] : NULL,
'description' => isset($reference['description']) ? $reference['description'] : NULL,
'langcode' => $this->configuration['langcode'],
'entity' => $entity,
'file_name' => $all_files[$reference['fid']]['filename'],
'file_path' => $file_url,
];
}
}
}
}
return new \ArrayIterator($files_found);
}