diff --git a/core/modules/migrate/src/Exception/ValidationException.php b/core/modules/migrate/src/Exception/ValidationException.php index 7b71b77..eeb5fe8 100644 --- a/core/modules/migrate/src/Exception/ValidationException.php +++ b/core/modules/migrate/src/Exception/ValidationException.php @@ -8,7 +8,7 @@ use Drupal\migrate\Plugin\MigrationInterface; /** - * Class ValidationException. + * Thrown when migrated content fails validation. */ class ValidationException extends MigrateException { diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php index d448180..587c265 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php @@ -26,6 +26,8 @@ * - overwrite_properties: (optional) A list of properties that will be * overwritten if an entity with the same ID already exists. Any properties * that are not listed will not be overwritten. + * - validate: (optional) Boolean, indicates if the entity should be validated, + * defaults to FALSE. * * Example: * @@ -44,6 +46,9 @@ * with the original source values. Updates done to 'field_example' would be * preserved because 'field_example' is not included in 'overwrite_properties' * configuration. + * + * The content will be validated because the configuration 'validate: true' was + * set. * @code * id: custom_article_migration * label: Custom article migration @@ -75,6 +80,7 @@ * overwrite_properties: * - title * - body + * validate: true * @endcode * * @see \Drupal\migrate\Plugin\migrate\destination\EntityRevision @@ -176,7 +182,7 @@ protected function save(ContentEntityInterface $entity, array $old_destination_i } /** - * Whether or not the entity needs validation. + * Gets the validate configuration key. * * @return bool * TRUE if validation is needed, FALSE otherwise. diff --git a/core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php index 7d72c43..4a76a29 100644 --- a/core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php +++ b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php @@ -11,7 +11,8 @@ use Drupal\user\Entity\User; /** - * Tests the EntityContentBase destination. + * Tests the validation of a migrated entity and that exceptions are thrown as + * necessary. * * @group migrate */ @@ -42,12 +43,7 @@ protected function setUp() { \Drupal::service('event_dispatcher')->addListener(MigrateEvents::IDMAP_MESSAGE, array($this, 'mapMessageRecorder')); // Make sure that a user with uid 2 exists. User::create(['name' => $this->randomMachineName(), 'uid' => 2, 'status' => 1])->save(); - } - /** - * Tests entity validation. - */ - public function testValidation() { // Migration definition. $definition = [ 'migration_tags' => ['ValidationTest'], @@ -89,7 +85,12 @@ public function testValidation() { // Execute the migration. $executable = new MigrateExecutable($migration); $executable->import(); + } + /** + * Tests entity validation. + */ + public function testValidation() { // First message should have 2 validation errors. $this->assertEquals('1: Name: may not be longer than 32 characters., The referenced entity (user: 1) does not exist.', $this->messages[0]);