Mercurial > hg > isophonics-drupal-site
comparison modules/contrib/migrate_plus/src/Entity/Migration.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\migrate_plus\Entity; | |
4 | |
5 use Drupal\Core\Cache\Cache; | |
6 use Drupal\Core\Config\Entity\ConfigEntityBase; | |
7 use Drupal\Core\Entity\EntityTypeInterface; | |
8 | |
9 /** | |
10 * Defines the Migration entity. | |
11 * | |
12 * The migration entity stores the information about a single migration, like | |
13 * the source, process and destination plugins. | |
14 * | |
15 * @ConfigEntityType( | |
16 * id = "migration", | |
17 * label = @Translation("Migration"), | |
18 * entity_keys = { | |
19 * "id" = "id", | |
20 * "label" = "label", | |
21 * "weight" = "weight" | |
22 * } | |
23 * ) | |
24 */ | |
25 class Migration extends ConfigEntityBase implements MigrationInterface { | |
26 | |
27 /** | |
28 * The migration ID (machine name). | |
29 * | |
30 * @var string | |
31 */ | |
32 protected $id; | |
33 | |
34 /** | |
35 * The human-readable label for the migration. | |
36 * | |
37 * @var string | |
38 */ | |
39 protected $label; | |
40 | |
41 /** | |
42 * {@inheritdoc} | |
43 */ | |
44 protected function invalidateTagsOnSave($update) { | |
45 parent::invalidateTagsOnSave($update); | |
46 Cache::invalidateTags(['migration_plugins']); | |
47 } | |
48 | |
49 /** | |
50 * {@inheritdoc} | |
51 */ | |
52 protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) { | |
53 parent::invalidateTagsOnDelete($entity_type, $entities); | |
54 Cache::invalidateTags(['migration_plugins']); | |
55 } | |
56 | |
57 /** | |
58 * Create a configuration entity from a core migration plugin's configuration. | |
59 * | |
60 * @param string $plugin_id | |
61 * ID of a migration plugin managed by MigrationPluginManager. | |
62 * @param string $new_plugin_id | |
63 * ID to use for the new configuration entity. | |
64 * | |
65 * @return \Drupal\migrate_plus\Entity\MigrationInterface | |
66 * A Migration configuration entity (not saved to persistent storage). | |
67 */ | |
68 public static function createEntityFromPlugin($plugin_id, $new_plugin_id) { | |
69 /** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface $plugin_manager */ | |
70 $plugin_manager = \Drupal::service('plugin.manager.migration'); | |
71 $migration_plugin = $plugin_manager->createInstance($plugin_id); | |
72 $entity_array['id'] = $new_plugin_id; | |
73 $entity_array['migration_tags'] = $migration_plugin->get('migration_tags'); | |
74 $entity_array['label'] = $migration_plugin->label(); | |
75 $entity_array['source'] = $migration_plugin->getSourceConfiguration(); | |
76 $entity_array['destination'] = $migration_plugin->getDestinationConfiguration(); | |
77 $entity_array['process'] = $migration_plugin->getProcess(); | |
78 $entity_array['migration_dependencies'] = $migration_plugin->getMigrationDependencies(); | |
79 $migration_entity = static::create($entity_array); | |
80 return $migration_entity; | |
81 } | |
82 | |
83 } |