diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php index ddf5629..607cc38 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php @@ -6,18 +6,18 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; +use Drupal\Core\Entity\EntityMalformedException; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\source\SourcePluginBase; use Drupal\migrate\Plugin\MigrationInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Drupal content entity source from database. + * Content entity source from current version of Drupal. * * @MigrateSource( - * id = "entity", + * id = "content_entity", * source_module = "migrate_drupal", * deriver = "\Drupal\migrate_drupal\Plugin\migrate\source\ContentEntityDeriver", * ) @@ -63,9 +63,9 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition $this->entityFieldManager = $entity_field_manager; $this->entityType = $this->entityTypeManager->getDefinition($plugin_definition['entity_type']); if (!$this->entityType instanceof ContentEntityTypeInterface) { - throw new InvalidPluginDefinitionException($plugin_id, 'The "entity" source plugin only supports content entities.'); + throw new InvalidPluginDefinitionException($plugin_id, 'The "content_entity" source plugin only supports content entities.'); } - if (!empty($this->configuration['bundle']) && !$this->entityType->getKey('bundle')) { + if (!empty($this->configuration['bundle']) && !$this->entityType->hasKey('bundle')) { throw new InvalidPluginDefinitionException('A bundle was provided but the entity type is not bundleable.'); } parent::__construct($configuration + ['bundle' => NULL], $plugin_id, $plugin_definition, $migration); @@ -89,7 +89,7 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function __toString() { - return (string) sprintf('%s source', $this->entityType->id()); + return (string) sprintf('%s source', $this->entityType->getLabel()); } /** @@ -104,7 +104,7 @@ protected function initializeIterator() { } /** - * Loads and yields a single entity one at a time. + * Loads and yields entities, one at a time. * * @param array $ids * The entity IDs. @@ -128,7 +128,7 @@ protected function yieldEntities(array $ids) { /** * Convert entity to array. * - * Make all IDs flat values. All other values are returned as per + * Makes all IDs into flat values. All other values are returned as per * $entity->toArray(), which is a nested array. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity @@ -147,7 +147,7 @@ protected function toArray(ContentEntityInterface $entity) { unset($return[$id]); $return[$id] = reset($reset); if (empty($return[$id])) { - throw new MigrateException(sprintf('Entity of type %s and id %s is missing its id.', $entity->getEntityType(), $entity->id())); + throw new EntityMalformedException(sprintf('Entity of type %s and id %s is missing its id.', $entity->getEntityTypeId(), $entity->id())); } } return $return; diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntityDeriver.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntityDeriver.php index 38050ca..9b38a6a 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntityDeriver.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntityDeriver.php @@ -8,6 +8,9 @@ use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +/** + * Deriver for content entity source plugins. + */ class ContentEntityDeriver extends DeriverBase implements ContainerDeriverInterface { /** diff --git a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php index f290c19..30b35ec 100755 --- a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php @@ -184,10 +184,10 @@ protected function setUp() { * Tests user source plugin. */ public function testUserSource() { - $userSource = $this->sourcePluginManager->createInstance('entity:user', [], $this->migration); + $userSource = $this->sourcePluginManager->createInstance('content_entity:user', [], $this->migration); $this->migration->expects(self::once())->method('getSourcePlugin')->willReturn($userSource); $this->migration->expects(self::once())->method('getDestinationIds')->willReturn([1]); - $this->assertSame('user source', $userSource->__toString()); + $this->assertSame('User source', $userSource->__toString()); $ids = $userSource->getIds(); $this->assertArrayHasKey('langcode', $ids); $this->assertArrayHasKey('uid', $ids); @@ -216,10 +216,10 @@ public function testFileSource() { ]); $file->save(); - $fileSource = $this->sourcePluginManager->createInstance('entity:file', [], $this->migration); + $fileSource = $this->sourcePluginManager->createInstance('content_entity:file', [], $this->migration); $this->migration->expects(self::once())->method('getSourcePlugin')->willReturn($fileSource); $this->migration->expects(self::once())->method('getDestinationIds')->willReturn([1]); - $this->assertSame('file source', $fileSource->__toString()); + $this->assertSame('File source', $fileSource->__toString()); $ids = $fileSource->getIds(); $this->assertArrayHasKey('fid', $ids); $fields = $fileSource->fields(); @@ -240,11 +240,11 @@ public function testFileSource() { * Tests node source plugin. */ public function testNodeSource() { - $nodeSource = $this->sourcePluginManager->createInstance('entity:node', ['bundle' => $this->bundle], $this->migration); + $nodeSource = $this->sourcePluginManager->createInstance('content_entity:node', ['bundle' => $this->bundle], $this->migration); $this->migration->expects(self::exactly(2))->method('getSourcePlugin')->willReturn($nodeSource); $this->migration->expects(self::at(0))->method('getDestinationIds')->willReturn([1, 'en']); $this->migration->expects(self::at(1))->method('getDestinationIds')->willReturn([2, 'fr']); - $this->assertSame('node source', $nodeSource->__toString()); + $this->assertSame('Content source', $nodeSource->__toString()); $ids = $nodeSource->getIds(); $this->assertArrayHasKey('langcode', $ids); $this->assertArrayHasKey('nid', $ids); @@ -286,10 +286,10 @@ public function testMediaSource() { ]); $media->save(); - $mediaSource = $this->sourcePluginManager->createInstance('entity:media', ['bundle' => 'image'], $this->migration); + $mediaSource = $this->sourcePluginManager->createInstance('content_entity:media', ['bundle' => 'image'], $this->migration); $this->migration->expects(self::once())->method('getSourcePlugin')->willReturn($mediaSource); $this->migration->expects(self::once())->method('getDestinationIds')->willReturn([1]); - $this->assertSame('media source', $mediaSource->__toString()); + $this->assertSame('Media source', $mediaSource->__toString()); $ids = $mediaSource->getIds(); $this->assertArrayHasKey('langcode', $ids); $this->assertArrayHasKey('mid', $ids); @@ -319,11 +319,11 @@ public function testTermSource() { ]); $term2->save(); - $termSource = $this->sourcePluginManager->createInstance('entity:taxonomy_term', ['bundle' => $this->vocabulary], $this->migration); + $termSource = $this->sourcePluginManager->createInstance('content_entity:taxonomy_term', ['bundle' => $this->vocabulary], $this->migration); $this->migration->expects(self::exactly(2))->method('getSourcePlugin')->willReturn($termSource); $this->migration->expects(self::at(0))->method('getDestinationIds')->willReturn([1]); $this->migration->expects(self::at(1))->method('getDestinationIds')->willReturn([2]); - $this->assertSame('taxonomy_term source', $termSource->__toString()); + $this->assertSame('Taxonomy term source', $termSource->__toString()); $ids = $termSource->getIds(); $this->assertArrayHasKey('langcode', $ids); $this->assertArrayHasKey('tid', $ids);