diff --git a/core/modules/migrate/src/Plugin/MigrationPluginManager.php b/core/modules/migrate/src/Plugin/MigrationPluginManager.php index 7714b2c..aefeee7 100644 --- a/core/modules/migrate/src/Plugin/MigrationPluginManager.php +++ b/core/modules/migrate/src/Plugin/MigrationPluginManager.php @@ -3,6 +3,7 @@ namespace Drupal\migrate\Plugin; use Drupal\Component\Graph\Graph; +use Drupal\Component\Plugin\CategorizingPluginManagerInterface; use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -21,7 +22,7 @@ /** * Plugin manager for migration plugins. */ -class MigrationPluginManager extends DefaultPluginManager implements MigrationPluginManagerInterface, MigrateBuildDependencyInterface { +class MigrationPluginManager extends DefaultPluginManager implements MigrationPluginManagerInterface, MigrateBuildDependencyInterface, CategorizingPluginManagerInterface { /** * Provides default values for migrations. @@ -70,11 +71,10 @@ public function processDefinition(&$definition, $plugin_id) { parent::processDefinition($definition, $plugin_id); // Loop over each of the definitions and tag it as config or content. - /** @var \Drupal\migrate\Plugin\MigratePluginManagerInterface $migrate_plugin_manager */ - $migrate_plugin_manager = \Drupal::getContainer() - ->get('plugin.manager.migrate.destination'); - $destination = $migrate_plugin_manager->getDefinition($definition['destination']['plugin'], FALSE); - if (!empty($destination['class'])) { + $destination_definition = \Drupal::getContainer() + ->get('plugin.manager.migrate.destination') + ->getDefinition($definition['destination']['plugin'], FALSE); + if (!empty($destination_definition['class'])) { $definition += [ 'migration_tags' => [], ]; @@ -87,7 +87,7 @@ public function processDefinition(&$definition, $plugin_id) { $is_already_assigned = function ($existing_tags) { return in_array('Configuration', $existing_tags) || in_array('Content', $existing_tags); }; - if ($is_config_class($destination['class']) && !$is_already_assigned($definition['migration_tags'])) { + if ($is_config_class($destination_definition['class']) && !$is_already_assigned($definition['migration_tags'])) { $definition['migration_tags'][] = 'Configuration'; } // Default to content. @@ -316,4 +316,31 @@ protected function classInArray($plugin_class, array $classes) { return FALSE; } + /** + * @inheritDoc + */ + public function getCategories() { + $tags = array_column($this->getDefinitions(), 'migration_tags'); + $flattened = []; + array_walk_recursive($tags, function($tag) use (&$flattened) { + $flattened[] = $tag; + }); + $return = array_unique($flattened); + sort($return); + return $return; + } + + /** + * @inheritDoc + */ + public function getSortedDefinitions(array $definitions = NULL) { + // TODO: Implement getSortedDefinitions() method. + } + + /** + * @inheritDoc + */ + public function getGroupedDefinitions(array $definitions = NULL) { + // TODO: Implement getGroupedDefinitions() method. + } } diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/CategorizationTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/CategorizationTest.php index 4d9378d..8685fb0 100644 --- a/core/modules/migrate/tests/src/Kernel/Plugin/CategorizationTest.php +++ b/core/modules/migrate/tests/src/Kernel/Plugin/CategorizationTest.php @@ -10,7 +10,7 @@ * * @group migrate */ -class DestinationCategoryTest extends MigrateDrupalTestBase { +class CategorizationTest extends MigrateDrupalTestBase { /** * {@inheritdoc} @@ -63,7 +63,7 @@ protected function setUp() { /** * Tests tagging migrations as configuration or content. */ - public function testTaggedConfigurationContentAlter() { + public function testTaggedConfigurationTypes() { /** @var MigrationPluginManager $migrationManager */ $migrationManager = \Drupal::service('plugin.manager.migration'); $tags = ['Configuration', 'Content']; @@ -229,4 +229,20 @@ public function testTaggedConfigurationContentAlter() { } } + /** + * Tests default categories. + */ + public function testGetCategories() { + /** @var MigrationPluginManager $migrationManager */ + $migrationManager = \Drupal::service('plugin.manager.migration'); + $actual = $migrationManager->getCategories(); + $expected = [ + 'Configuration', + 'Content', + 'Drupal 6', + 'Drupal 7', + ]; + $this->assertEquals($expected, $actual); + } + }