comparison core/modules/taxonomy/src/Plugin/migrate/D6TermNodeDeriver.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\taxonomy\Plugin\migrate;
4
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Component\Plugin\PluginManagerInterface;
7 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
8 use Drupal\migrate\Plugin\MigrationDeriverTrait;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10
11 /**
12 * Deriver for Drupal 6 term node migrations based on vocabularies.
13 */
14 class D6TermNodeDeriver extends DeriverBase implements ContainerDeriverInterface {
15 use MigrationDeriverTrait;
16
17 /**
18 * The base plugin ID this derivative is for.
19 *
20 * @var string
21 */
22 protected $basePluginId;
23
24 /**
25 * The migration plugin manager.
26 *
27 * @var \Drupal\Component\Plugin\PluginManagerInterface
28 */
29 protected $migrationPluginManager;
30
31 /**
32 * D6TermNodeDeriver constructor.
33 *
34 * @param string $base_plugin_id
35 * The base plugin ID this derivative is for.
36 * @param \Drupal\Component\Plugin\PluginManagerInterface $migration_plugin_manager
37 * The migration plugin manager.
38 */
39 public function __construct($base_plugin_id, PluginManagerInterface $migration_plugin_manager) {
40 $this->basePluginId = $base_plugin_id;
41 $this->migrationPluginManager = $migration_plugin_manager;
42 }
43
44 /**
45 * {@inheritdoc}
46 */
47 public static function create(ContainerInterface $container, $base_plugin_id) {
48 return new static(
49 $base_plugin_id,
50 $container->get('plugin.manager.migration')
51 );
52 }
53
54 /**
55 * {@inheritdoc}
56 */
57 public function getDerivativeDefinitions($base_plugin_definition, $base_plugin_definitions = NULL) {
58 try {
59 foreach (static::getSourcePlugin('d6_taxonomy_vocabulary') as $row) {
60 $source_vid = $row->getSourceProperty('vid');
61 $definition = $base_plugin_definition;
62 $definition['source']['vid'] = $source_vid;
63 // migrate_drupal_migration_plugins_alter() adds to this definition.
64 $this->derivatives[$source_vid] = $definition;
65 }
66 }
67 catch (\Exception $e) {
68 // It is possible no D6 tables are loaded so just eat exceptions.
69 }
70 return $this->derivatives;
71 }
72
73 }