TermNode.php in Zircon Profile 8
File
core/modules/taxonomy/src/Plugin/migrate/builder/d6/TermNode.php
View source
<?php
namespace Drupal\taxonomy\Plugin\migrate\builder\d6;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateMessage;
use Drupal\migrate\MigrateTemplateStorage;
use Drupal\migrate\Plugin\migrate\builder\BuilderBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TermNode extends BuilderBase implements ContainerFactoryPluginInterface {
protected $templateStorage;
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateTemplateStorage $template_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->templateStorage = $template_storage;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('migrate.template_storage'));
}
protected function getVocabularyIdMap(array $source) {
$map = [];
$template = $this->templateStorage
->getTemplateByName('d6_taxonomy_vocabulary');
$template['source'] += $source;
$migration = Migration::create($template);
$executable = new MigrateExecutable($migration, new MigrateMessage());
$process = array_intersect_key($template['process'], $migration
->getDestinationPlugin()
->getIds());
foreach ($migration
->getSourcePlugin() as $source_row) {
$executable
->processRow($source_row, $process);
$map[$source_row
->getSourceProperty('vid')] = $source_row
->getDestinationProperty('vid');
}
return $map;
}
public function buildMigrations(array $template) {
$migrations = [];
foreach ($this
->getVocabularyIdMap($template['source']) as $source_vid => $destination_vid) {
$values = $template;
$values['id'] .= '__' . $source_vid;
$values['source']['vid'] = $source_vid;
$migration = Migration::create($values);
$migration
->setProcessOfProperty($destination_vid, 'tid');
$migrations[] = $migration;
}
return $migrations;
}
}
Classes
Name |
Description |
TermNode |
Plugin annotation
@PluginID("d6_term_node"); |